似乎你可以用JsonWriter类做一些事情:
JsonObject *pJsonObj = new JsonObject();
pJsonObj->Construct();
String *pStrProductKey = new String(L"product");
String *pStrStockKey = new String(L"stock");
JsonString *pStrProduct1 = new JsonString(L"iPhone 5S");
JsonNumber *pStrIPhoneStock = new JsonNumber(7);
pJsonObj->Add(pStrProductKey, pStrProduct1);
pJsonObj->Add(pStrStockKey, pStrIPhoneStock);
/* Replace 256 with the amount of space you think you might
need for the string. */
char *pComposeBuf = new char[256];
result res = JsonWriter::Compose(pJsonObj, pComposeBuf, 256);
String s(pComposeBuf);
s
现在将包含字符串"{"product":"iPhone 5S","stock":7}"
。