JSON解析在Android应用程序 [英] Json Parsing in Android Application

查看:137
本文介绍了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 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) {
            }       
}

这篇关于JSON解析在Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆