我需要使用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”(数据中第一个数组的第一个值)。
你有什么想法吗?
答案 0 :(得分:8)
请注意,“data”是一个数组数组。如果您想要检索上述内容,请尝试以下操作:
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)]);
}