我试图解析这个json数组和json对象,但是给我错误并且没有收到任何数据,你能帮我解析一下吗;
这是我的json链接:
http://almahdishop.com/api/posts.json?fields=id,title,thumb&limit=10
我的代码:
JSONArray jsonarray = new JSONArray(jsStr);
for (int i = 0; i <jsonarray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject jso = jsonarray.getJSONObject(i);
map.put("id_product", jso.getString("id"));
map.put("name", jso.getString("title"));
map.put("model","");
map.put("price", "14000");
map.put("oldprice", "14000");
map.put("logo", jso.getString("thumb"));
arraylist.add(map);
}
答案 0 :(得分:0)
解析这个json如下:
try {
JSONObject jsonObject = new JSONObject(jsonString);
JSONArray array = jsonObject.getJSONArray("items");
for(int i=0;i<array.length();i++){
JSONObject obj = (JSONObject) array.get(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
答案 1 :(得分:0)
有些人喜欢这个
try {
JSONObject data = new JSONObject(jsonString);
JSONArray itemsArray = data.getJSONArray("items");
for (int i = 0; i <itemsArray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject jso = itemsArray .getJSONObject(i);
map.put("id_product", jso.getString("id"));
map.put("name", jso.getString("title"));
map.put("model","");
map.put("price", "14000");
map.put("oldprice", "14000");
map.put("logo", jso.getString("thumb"));
arraylist.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
答案 2 :(得分:0)
我认为问题来自解析。 请使用org.JSON.simple.-111.jar。