4

我需要用 rapidjson 稀疏这种 json :

{
    "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]
    ]
}

要获得 id "source_code" 的值非常简单:

d.Parse<0>(json); printf("source_code" = %s\n", document["source_code"].GetString());

但是我无法成功检索数据的值。例如,我希望能够检索“2010-01-12”和“-0.010565362832445”(数据中第一个数组的两个第一个值)。

你有什么主意吗 ?

4

1 回答 1

9

请注意,“数据”是一个数组数组。如果您想检索上面所说的内容,请尝试以下操作:

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)]);
}
于 2014-04-19T15:14:09.873 回答