Rapidjson,在另一个数组的数组内部获取一个值 [英] Rapidjson , get a value inside an array of another array

查看:1342
本文介绍了Rapidjson,在另一个数组的数组内部获取一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用rapidjson稀释这种json:

I need to sparse a json of this kind with rapidjson :

{
    "errors":{},
    "id":2326625,
    "source_code":"GOOG",
    "data":
    [
        ["2010-01-12",-0.010565362832445,-0.010432881793793,-0.010144243731464,-0.017685262281432,-0.3275071624503],
        ["2010-01-13",-0.036084889870791,-0.016333087890756,-0.024003268530183,-0.0057299789787753,0.33911818660036],
        ["2010-01-14",0.012849006806501,0.0098673018033346,0.015523616828298,0.0047058823529412,-0.34735779281787],
        ["2010-01-15",0.013166015223205,-0.0010781671159029,-0.0081756037236783,-0.016698910497913,0.28200124010685]
    ]
}

要获得idsource_code的值非常简单:

To get value of id "source_code" quite simple :

d.Parse< 0>(json);
的printf(source_code=%s\\\
,文件[source_code]的GetString());

但是我能不能成功检索数据的价值。举例来说,我想能够检索2010-01-12和-0.010565362832445(在数据中的第一阵列的两个第一值)。

However i can't succeed to retrieve value of data. For instance, i would like to be able to retrieve "2010-01-12" and "-0.010565362832445" (The two first value of the first array in data).

你有什么想法?

推荐答案

请注意,数据是一个数组数组如果你想检索你上面说的话,请尝试:

Note that "data" is an array of arrays. If you want to retrieve what you said above, try this:

const rapidjson::Value& b = d["data"];

for (rapidjson::SizeType i = 0; i < b.Size(); i++)
{
    const rapidjson::Value& c = b[i];

    printf("%s \n",c[rapidjson::SizeType(0)]);
    printf("%.20f \n",c[rapidjson::SizeType(1)]);
}

这篇关于Rapidjson,在另一个数组的数组内部获取一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆