1

JavaScript 関数に挿入するための多くのパラメーターを持つ JsonObject があります。

メソッド ToString は JsonNull 専用であり、JsonObject 用ではありません。

JsonObject を JsonNull にキャストできません。

これは私のコードです:

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

これを行う方法はありますか?

4

2 に答える 2

1

以下のメソッドを使用して、jsonObject を渡し、結果を文字列として取得します。

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;
}
于 2013-11-14T18:37:30.547 に答える
0

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}"

于 2013-09-19T12:39:17.100 に答える