#include <json/json.h>
#include <iostream>
#include <string>
using namespace std; int main(){
Json::Value root;
Json::FastWriter writer; int a = ;
int b = ;
int c = ;
int d = ; root["mprotocolType"] = a;
root["dstdeviceID"] = b;
root["mprotocolID"] = c;
root["mver"] = d; string receiveDataToRedis = writer.write(root); cout << "data: " << receiveDataToRedis << endl; return ; }
编译:
# g++ test.cpp -I/usr/local/include /usr/local/lib/-ljson_linux-gcc-4.4.5_libmt.a
运行:
#./a.out
输出;
data: {"dstdeviceID":456,"mprotocolID":5858,"mprotocolType":123,"mver":4}
可以发现,jsoncpp的字段排序默认是按照字母的。