如何采用了android解析json的网址是什么? [英] How to parse json url using android?
本文介绍了如何采用了android解析json的网址是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要解析JSON的网址,我的JSON的URL包含以下结构
I want parse json url,my json url contains following structures
{"content":{"item":[{"category":"xxx"},{"category":"yy"} ]}}
如何解读这种结构,有人知道给例如JSON解析器为。
how to read this structure,anybody knows give example json parser for that.
感谢
推荐答案
这code会帮你解析JSON你。
This code will help you to parse yours json.
String jsonStr = "{\"content\":{\"item\":[{\"category\":\"xxx\"},{\"category\":\"yy\"} ]}}";
try {
ArrayList<String> categories = new ArrayList<String>();
JSONObject obj = new JSONObject(jsonStr);
JSONObject content = obj.getJSONObject("content");
JSONArray array = content.getJSONArray("item");
for(int i = 0, count = array.length();i<count;i++)
{
JSONObject categoty = array.getJSONObject(i);
categories.add(categoty.getString("category"));
}
} catch (JSONException e) {
e.printStackTrace();
}
这篇关于如何采用了android解析json的网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文