I have a JsonObject with many parameters for insert in a JavaScript function.

The method ToString is only for a JsonNull and not for a JsonObject.

I can't cast my JsonObject in a JsonNull.

This is my code :

{void
 WebViewer::ExecuteScriptInWebView(JsonObject jsonObject) {
__pWeb->EvaluateJavascriptN("test.execute("+jsonObject->ToString()+")");
}

Does it exist a method to do this ?

有帮助吗?

解决方案 2

Seems like something you could do with the JsonWriter class:

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 will now contain the string "{"product":"iPhone 5S","stock":7}".

其他提示

Use the below method ,Pass your jsonObject and get the result as string

String YourClass::GetJsonString(IJsonValue* pVal) {

String jsonString;

char* pBuf = new char[4096];
result r = JsonWriter::Compose(pValue, pComposeBuf, 4096);
if (r == E_SUCCESS) {
    jsonString = pComposeBuf;
} else {
    jsonString = L"";
}
delete[] pBuff;

return jsonString;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top