获得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的解析,在机器人/