×
Namespaces

Variants
Actions

怎样解析JSON

From Nokia Developer Wiki
Jump to: navigation, search
WP Metro Icon File.png
WP Metro Icon Web.png
SignpostIcon WP7 70px.png
Article Metadata

代码示例
兼容于
文章
翻译:
最后由 hamishwillee 在 16 Jul 2013 编辑

JSON是很常见的一种格式。本文说明怎样在Symbian C++中解析JSON,并且提供link到有关Qt和Windows Phone的JSON解析的文章。

Symbian parsing library

Symbian C++的解析器叫做's60-json-library。它被放在这里,你可以在这里下载它:Media:S60-json-library.zip

下面的代码演示了怎样用这个API解析JSON,它解析了Google翻译返回的JSON数据。

_LIT(KTestFormatedJson, "{\"responseData\": {\"translatedText\":\"אני ילד\"}, \"responseDetails\": null, \"responseStatus\": 200}");
 
CJsonBuilder* jsonBuilder = CJsonBuilder::NewL();
// this will create json string representation in memory
jsonBuilder->BuildFromJsonStringL(iKTestFormatedJson);
 
CJsonObject* rootObject;
CJsonObject* textObj;
jsonBuilder->GetDocumentObject(rootObject);
 
if(rootObject)
{
TBuf<256> message;
rootObject->GetObjectL(_L("responseData"),textObj);
textObj->GetStringL(_L("translatedText"),message);
}
 
// we need manually release created object
delete rootObject;
 
// releases only jsonBuilder object, not objects which was created by him
delete jsonBuilder;

JSON Parsing in Qt

  • QJson - 在Qt中解析JSON的类库。

JSON Parsing in Windows Phone 7

This page was last modified on 16 July 2013, at 10:59.
82 page views in the last 30 days.
×