JSON解析在Android应用程序应用程序、JSON、Android

由网友(招财猫的小铃铛)分享简介:完成XML SAX解析现在我工作的JSON解析在我的应用程序后。在这里,我提供你的Json After completing the XML SAX Parsing now I am working on JSON Parsing in my application. Here I am providing you...

完成XML SAX解析现在我工作的JSON解析在我的应用程序后。在这里,我提供你的Json

After completing the XML SAX Parsing now I am working on JSON Parsing in my application. Here I am providing you the Json

Response : {"menu": {
              "id": "file",
              "value": "File",
              "popup": {
                "menuitem": [
                  {"value": "New", "onclick": "CreateNewDoc()"},
                  {"value": "Open", "onclick": "OpenDoc()"},
                  {"value": "Close", "onclick": "CloseDoc()"}
                ]
              }
            }}

现在我已经提到JSON解析之一,他们创造了一个的jstring对象的例子,我有一个疑问,在那个特定的线,是为下:

Now I had referred one example of Json Parsing in which they had created a jString Object and I had a doubt in that particular line which is as under :

private String jString = "{"menu":    {"id": "file", "value": "File", "

任何人都可以让我一下吧,请明确。 完整的示例的链接是为下:

Can anyone make me clear about it please. The Link of the Complete Example is as Under:

http://www.androidcompetencycenter.com/2009/10 / JSON-解析功能于安卓/

推荐答案

您可以从这样的响应(我假设你知道如何照顾反应)得到一个JSON对象

You can get a JSON object from the response like this (I assume you know how to take care of the response):

String[] file = null;

/* Make a JSON object from your response, yourResponse is a String containing
the whole response */
JSONObject jsonObject = new JSONObject(yourResponse);

/* Your "menu": array from your response */
JSONArray infoArray = jsonObject.getJSONArray("menu"); 

/* If the array contains multiple items, loop it
through the infoArray's size */
for (int i = 0; i < infoArray.length(); i++) {  
        try {    
          //Get the value inside "id"
          file[i] = infoArray.getJSONObject(i).optString("id");                  
            } catch (JSONException e) {
            }       
}
阅读全文

相关推荐

最新文章