用JSONCPP格式化以下数据,我需要C++代码:{ "appkey": "a20d86c00ff80c14e05305660f0adc99", "timestamp": "1585550060", "sign": "3507fffd6121603a600732e72dd8b9b1", "workStationCode": "1101-pack-zdx", "MO": "200000031624", "WO": "1110 线-200000031624-PACK", "machineNo": "设备编号", "laneNo": "轨道", "fixtureNo": "夹具二维码", "staffNo": "操作员工号", "workTime": "2022-04-01 09:30:12", "finishTime": "2022-04-01 09:33:15", "pcList": [ { "seq": "1", "barcode": "小板二维码 1", "barcode2": "商标二维码", "progName": "LW-[306L033(VB100-8SP1)-01-B]-B07(T1A)-XN-V1.0", "productModel": "VB100-8SP1", "sn": "1234", "productDate": "2022-04-01", "procName": "性能", "procCode": "XN", "status": "PASS", "NGReason": "", "dataList": [ { "seq": "1", "testItem": "charge_v", "testName": "充电电压", "testResult": "PASS", "testUnits": "V", "dataValue": "4.3", "upperLimit": "4.5", "lowerLimit": "4.2" } ], "charList": [ { "seq": "1", "testItem": "read_sn", "testName": "读 SN", "testResult": "PASS", "charValue": "G8V10926394273" } ] } ] }
时间: 2023-03-26 12:02:03 浏览: 112
C++使用JsonCpp库操作json格式数据示例
5星 · 资源好评率100%
以下是用JSONCPP格式化数据的C代码:
#include <iostream>
#include <json/json.h>
int main() {
Json::Value root;
root["appkey"] = "a20d86c00ff80c14e05305660fadc99";
root["timestamp"] = "158555006";
root["sign"] = "3507fffd6121603a600732e72dd8b9b1";
root["workStationCode"] = "1101-pack-zdx";
root["MO"] = "200000031624";
root["WO"] = "111 线-200000031624-PACK";
root["machineNo"] = "设备编号";
root["laneNo"] = "轨道";
root["fixtureNo"] = "夹具二维码";
root["staffNo"] = "操作员工号";
root["workTime"] = "2022-04-01 09:30:12";
root["finishTime"] = "2022-04-01 09:33:15";
Json::Value pcList(Json::arrayValue);
Json::Value pc;
pc["seq"] = "1";
pc["barcode"] = "小板二维码 1";
pc["barcode2"] = "商标二维码";
pc["progName"] = "LW-[306L033(VB100-8SP1)-01-B]-B07(T1A)-XN-V1.";
pc["productModel"] = "VB100-8SP1";
pc["sn"] = "1234";
pc["productDate"] = "2022-04-01";
pc["procName"] = "性能";
pc["procCode"] = "XN";
pc["status"] = "PASS";
pc["NGReason"] = "";
Json::Value dataList(Json::arrayValue);
Json::Value data;
data["seq"] = "1";
data["testItem"] = "charge_v";
data["testName"] = "充电电压";
data["testResult"] = "PASS";
data["testUnits"] = "V";
data["dataValue"] = "4.3";
data["upperLimit"] = "4.5";
data["lowerLimit"] = "4.2";
dataList.append(data);
pc["dataList"] = dataList;
Json::Value charList(Json::arrayValue);
Json::Value charItem;
charItem["seq"] = "1";
charItem["testItem"] = "read_sn";
charItem["testName"] = "读 SN";
charItem["testResult"] = "PASS";
charItem["charValue"] = "G8V10926394273";
charList.append(charItem);
pc["charList"] = charList;
pcList.append(pc);
root["pcList"] = pcList;
Json::StreamWriterBuilder builder;
builder["indentation"] = "\t";
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
writer->write(root, &std::cout);
return ;
}
阅读全文