python 中的dict如下:
Dicts = {"Stain":{"ResultType": "Physics","Results": [{"Key": "KeyPoints","Title": "瑕疵区域","Unit": "","Value": stainlist,"Primitive":["faces"]},{"Key": "Num","Title": "数量","Unit": "个","Value": num},],"Score": 0,"Title": "斑"}}
利用c++的实现如下:
writer.StartObject();开始 {
writer.StartArray();开始 [
后面同理不在赘述
rapidjson::StringBuffer buffer;rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);writer.StartObject();writer.Key("Stain");writer.StartObject();writer.Key("ResultType");writer.String("Physics");//数组类型writer.Key("Results");writer.StartArray();writer.StartObject();writer.Key("Key");writer.String("KeyPoints");writer.Key("Title");writer.String("瑕疵点");writer.Key("Unit");writer.String("个");writer.Key("Value");writer.StartArray();for (int i = 0; i < filterContours.size(); i++) {writer.StartArray();for (int j = 0; j < filterContours[i].size(); j++) {writer.Int(filterContours[i][j].x);writer.Int(filterContours[i][j].y);}writer.EndArray();}writer.EndArray();writer.Key("Primitive");writer.String("faces");writer.EndObject();writer.StartObject();writer.Key("Key");writer.String("Num");writer.Key("Title");writer.String("数量");writer.Key("Unit");writer.String("个");writer.Key("Value");writer.Int(filterContours.size());writer.EndObject();writer.EndArray();writer.Key("Score");writer.Int(0);writer.Key("Title");writer.String("斑");writer.EndObject();writer.EndObject();jsonStr = buffer.GetString();printf("%s\n", buffer.GetString());