获得JSON结果在Android中 [英] getting Json result in Android

查看:93
本文介绍了获得JSON结果在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的Json问题:

我有这种格式的JSON

I have this formatted JSON

 {
 "Table1":[
  {
     "TableName":"LoadDistributor",
     "Description":"Distributor ",
     "MandatoryFlag":"1",
     "Status":"",
     "Priority":"0"
  },
  {
     "TableName":"LoadPrice",
     "Description":"Price ",
     "MandatoryFlag":"1",
     "Status":"",
     "Priority":"0"
  },
  {
     "TableName":"LoadProduct",
     "Description":"Product ",
     "MandatoryFlag":"1",
     "Status":"",
     "Priority":"0"
  },
  {
     "TableName":"RD.AlternativeProductDetail",
     "Description":"AltProdutDetail",
     "MandatoryFlag":"0",
     "Status":"",
     "Priority":"0"
  },
  {
     "TableName":"XA.vwTown",
     "Description":"Town ",
     "MandatoryFlag":"1",
     "Status":"",
     "Priority":"0"
  }

]
}

] }

Android版的Json处理方法是:

Android Json Processing method is:

   public String[] getStringArrayResponseJson(SoapPrimitive node, ArrayList<String> strings) {
    try{

        String result = node.toString();
        JSONObject json = new JSONObject(result);

        // Parsing
        JSONArray nameArray = json.names();
        JSONArray valArray = json.toJSONArray(nameArray);
        Log.i("@@@" , "===="+  valArray.length());
        for (int i = 0; i < valArray.length(); i++) {
            strings.add(valArray.getString(i));
        }

        json.put("sample key", "sample value");
        Log.i("REST", "<jsonobject>\n" + json.toString()
                + "\n</jsonobject>");
    }catch (JSONException e) {
    e.printStackTrace();
}

我的要求是我想要得到的表名到字符串[]或列表...我们该怎么做?

My requirement is I want to get the TableName into string[] or list... How we can do this?

请帮我什么是我的JSON处理方法错误:

Please help me what is the error in my json processing method:?

推荐答案

举例code,不知道它去上班。
我创建一个字符串只是为了它的缘故一个ArrayList。

Example code, not sure that its going to work. I create an ArrayList for the strings just for the sake of it.

ArrayList<String> list = new ArrayList<String>();
JSONArray array = jsonobject.getJSONArray("Table1");        
int max = array.length();
 for (int i = 0; i < max; i++) {
   JSONObject tmp = array.getJSONObject(i);
   list.add(tmp.getString("TableName"));
 }

可能是一个更快的方法,但只是一个例子。

Might be a quicker way but just for an example.

您可以阅读更多 http://www.androidcompetencycenter.com / 2009/10 / JSON的解析,在机器人/

这篇关于获得JSON结果在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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