本文介绍了解析JSON阵列的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我试图解析从这个 URL JSON数组。 JSON数组看起来是这样的。Hi i'm trying to parse json array from this url. The json array looks like this. [ { "id":1, "introtext":"\u041b\u0438\u043c\u0443\u0437\u0438\u043d\u0430\u0442\u0430 \u0435 \u043e\u0434 \u0430\u043c\u0435\u0440\u0438\u043a\u0430\u043d\u0441\u043a\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u0432\u043e \u0431\u0435\u043b\u0430 \u0431\u043e\u0458\u0430 \u0434\u043e\u043b\u0433\u0430 \u043e\u043a\u043e\u043b\u0443 8,5 \u043c\u0435\u0442\u0440\u0438. \u041e\u043f\u0440\u0435\u043c\u0435\u043d\u0430 \u0435 \u0441\u043e \u043a\u043b\u0438\u043c\u0430 \u0440\u0435\u0434, \u0422\u0412, \u0414\u0412\u0414 \u0438 \u0431\u0430\u0440. \u041c\u043e\u0436\u0430\u0442 \u0434\u0430 \u0441\u0435 \u0432\u043e\u0437\u0430\u0442 \u0434\u043e 9 \u043b\u0438\u0446\u0430. \u0421\u0435 \u0438\u0437\u043d\u0430\u0458\u043c\u0443\u0432\u0430 \u0441\u043e \u043d\u0430\u0448 \u0448\u043e\u0444\u0435\u0440.\n{AdmirorGallery}..\/katalog\/prevoz\/limo-servis-jasmina\/linkoln\/{\/AdmirorGallery}\n\u00a0", "image":"http:\/\/zasvadba.mk\/media\/k2\/items\/cache\/787ae9ec9023a82f5aa7e4c1a64f73cb_S.jpg", "title":"\u041b\u0438\u043c\u0443\u0437\u0438\u043d\u0430 \u041b\u0438\u043d\u043a\u043e\u043b\u043d", "catid":"20", "alias":"\u043b\u0438\u043c\u0443\u0437\u0438\u043d\u0430-\u043b\u0438\u043d\u043a\u043e\u043b\u043d-\u043b\u0438\u043c\u043e-\u0441\u0435\u0440\u0432\u0438\u0441-\u0458\u0430\u0441\u043c\u0438\u043d\u0430" }]我在做这在我的Java类I'm doing this in my java classtry { JSONfunctions j=new JSONfunctions(); JSONObject json = j.getJSONfromURL(url); Log.i("log_tag", json.toString()); String jsonvalues = json.getString("id"); Log.i("DARE", jsonvalues); } catch (Exception ex) { Log.e("log_tag", "Error getJSONfromURL "+ex.toString()); } }不过,这是行不通的,任何人可以帮助我分析我的JSON数组But it doesn't work, can anybody help me parse my json array推荐答案您需要根据字符串进行两次改变你目前的code u必须张贴在这里解析为JSON:you will need to make two changes in your current code according to string u have posted here for parsing as Json : 第一:修改 getJSONfromURL 方法的返回类型为 JSONArray 并返回 JSONArray $从它,而不是的JSONObject例如:First : change the return type of getJSONfromURL method to JSONArray and return JSONArray from it instead of JSONObjectFor example :public JSONArray getJSONfromURL(String url){ String str_response="response from server"; // convert response to JSONArray JSONArray json_Array=new JSONArray(str_response); return json_Array; //<< retun jsonArray} 二:更改code作为从获得价值 JsonArray :Second : change your code as for getting value from JsonArray :try { JSONfunctions j=new JSONfunctions(); JSONArray jArray = j.getJSONfromURL(url); Log.i("log_tag", jArray.toString()); for(int i=0;i<jArray.length();i++){ JSONObject json_data = jArray.getJSONObject(i); String jsonvalues = json_data.getString("id"); // .. get all value here Log.i("DARE", jsonvalues); } }catch (Exception ex) { Log.e("log_tag", "Error getJSONfromURL "+ex.toString()); } 这篇关于解析JSON阵列的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-09 13:59