Android如何解析json数组对象
json是种常用的数据传输格式,在android开发中,如何借助java语言实现对json数组对象的解析呢,请参阅下面的关键代码:
Java代码
- import org.json.JSONArray;
- import org.json.JSONObject;
- //jsonData的数据格式:[{ "id": "27JpL~jd99w9nM01c000qc", "version": "abc" },{ "id": "27JpL~j6UGE0LX00s001AH", "version": "bbc" },{ "id": "27JpL~j7YkM0LX01c000gt", "version": "Wa_" }]
- JSONArray arr = new JSONArray(jsonData);
- for (int i = 0; i < arr.length(); i++) {
- JSONObject temp = (JSONObject) arr.get(i);
- String id = temp.getString("id");
- String id = temp.getString("version");
- }
import org.json.JSONArray;import org.json.JSONObject;//jsonData的数据格式:[{ "id": "27JpL~jd99w9nM01c000qc", "version": "abc" },{ "id": "27JpL~j6UGE0LX00s001AH", "version": "bbc" },{ "id": "27JpL~j7YkM0LX01c000gt", "version": "Wa_" }]JSONArray arr = new JSONArray(jsonData);for (int i = 0; i < arr.length(); i++) { JSONObject temp = (JSONObject) arr.get(i); String id = temp.getString("id"); String id = temp.getString("version");}
相关推荐
somebodyoneday 2020-06-15
83163452 2020-01-28
adonislu 2020-01-10
baijinswpu 2020-01-01
adonislu 2019-12-31
xufankang 2019-12-19
somebodyoneday 2019-12-07
somebodyoneday 2019-10-30
ZCMUCZX 2016-04-14
adonislu 2020-06-02
baijinswpu 2020-02-19
adonislu 2020-02-14
baijinswpu 2019-12-28
abcx 2015-05-25
newthon 2019-10-21
iovaaron 2015-04-10
Dolphinsz 2016-04-25