简体   繁体   English

如何使tizen :: Web :: JsonObect toString?

[英]How make tizen::Web::JsonObect toString?

I have a JsonObject with many parameters for insert in a JavaScript function. 我有一个带有许多参数的JsonObject,可以在JavaScript函数中插入。

The method ToString is only for a JsonNull and not for a JsonObject. ToString方法仅适用于JsonNull,不适用于JsonObject。

I can't cast my JsonObject in a JsonNull. 我无法将JsonObject转换为JsonNull。

This is my code : 这是我的代码:

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

Does it exist a method to do this ? 是否存在执行此操作的方法?

Use the below method ,Pass your jsonObject and get the result as string 使用以下方法,传递您的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;
}

Seems like something you could do with the JsonWriter class: 似乎可以使用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 will now contain the string "{"product":"iPhone 5S","stock":7}" . s现在将包含字符串"{"product":"iPhone 5S","stock":7}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM