如何在C ++中解析JSON对象数组?

时间:2016-11-08 06:20:03

标签: c++ arrays json parsing object

我在使用C ++解析json时遇到问题。

{"id":1,"name":"Pablo","client_type":"customer","uid":"c63bab66",
"credit":10000.0,"valid_user":true,"can_clean":false,"can_detach":false,
"can_set_temp":false,"category":"VIP","category_low_percentage":20,
"category_medium_percentage":20,"category_high_percentage":20,
"bottle_holders":
[{"dispenser_index":8,"can_complementary_drink":true},
 {"dispenser_index":7,"can_complementary_drink":true},
 {"dispenser_index":6,"can_complementary_drink":true},
 {"dispenser_index":5,"can_complementary_drink":true},
 {"dispenser_index":4,"can_complementary_drink":true},
 {"dispenser_index":3,"can_complementary_drink":true},
 {"dispenser_index":2,"can_complementary_drink":true},
 {"dispenser_index":1,"can_complementary_drink":true}],
"errors":[]}

这就是我试图解析它的方式。

 json_unpack(usr,"{s:s, s:s, s:i, s:f, s:b, s:b, s:b, s:s, s:i, s:i, s:i, s:o, s:o}", "uid", &juid, "name", &jname,
                        "id", &id, "credit", &credit, "can_clean", &jcan_clean, "can_detach", &jcan_detach, 
                        "can_set_temp", &jcan_set_temp, "category", &jcategory, "category_low_percetage", &category_low_perc, 
                        "category_medium_percetage", &category_medium_perc, "category_high_percetage", &category_high_perc,
                        "bottle_holders", &jbottle_holders, "errors", &jerrors);

问题在于,当我尝试获取对象数组“jbottle_holders”的长度时,它为“0”。 我的猜测是我应该改变“s:o”来正确描述一系列对象。 你觉得怎么样?

0 个答案:

没有答案