拜托,请帮帮我..
我正在开发一个项目,我从 JSON格式的Web服务获取数据.我试图解析它,但我无法做到.我有这个json数据 –
我正在开发一个项目,我从 JSON格式的Web服务获取数据.我试图解析它,但我无法做到.我有这个json数据 –
{ "response": { "status": { "code": "1","message": "sucess","user_id": "1" },"foods": [ { "char": "A","content": [ { "food_name": "add Malt" },{ "food_name": "a la mode" },{ "food_name": "Almonds" } ] },{ "char": "Z","content": [ { "food_name": "Zebra Cakes" },{ "food_name": "Zucchini,Baby" },{ "food_name": "zxc" } ] } ] } }
从这里我成功地获得了“食物”阵列,但当我试图获得“内容”数组和food_name数据时,我陷入困境.
我正在使用此代码,但我没有得到任何解决方案,请检查此剪辑代码.
protected String doInBackground(String... args) { // Building Parameters List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("method","eat_tracking_details")); nameValuePairs.add(new BasicNameValuePair("uid",userid)); // getting JSON string from URL JSONObject json = jsonParser.makeHttpRequest(JSONParser.urlname,"GET",nameValuePairs); //System.out.println("****json*"+json); if (json != null) { try { JSONObject response = json.getJSONObject("response"); JSONObject status = response.getJSONObject("status"); code = status.getString("code"); JSONArray FoodArray = response.getJSONArray("foods"); for (int i = 0; i < FoodArray.length(); i++) { String character = FoodArray.getJSONObject(i).getString("char"); System.out.println("*****character****************"+character); JSONArray FoodNameArray = new JSONArray(FoodArray.getJSONObject(i).getString("content")); System.out.println("====================///////////"+FoodNameArray); for (int j = 0; j <FoodNameArray.length(); j++) { String Foodname = FoodArray.getJSONObject(j).getString("food_name"); System.out.println("@@@@@@@@@@@@@"+Foodname); } } } catch (JSONException e) { // TODO: handle exception } }
检查此网址以获取网络服务响应 –
WEB-SERVICE URL