如何将这些String Arraylist [{},{},{} ...]拆分为字符串或整数?

时间:2014-08-24 04:42:29

标签: android expandablelistview data-conversion

我有,

[{"GroupPosition":0,"ChildPosition":0},{"GroupPosition":0,"ChildPosition":1},{"GroupPosition":1,"ChildPosition":0}]

如何将它们分成: GroupPosition:

[0,0,1] or {0,0,1}

ChildPosition:

[0,0,0] or {0,0,0}

1 个答案:

答案 0 :(得分:0)

您的输入是json格式。考虑我的代码是样本。

private static ArrayList<String> array_1 = new ArrayList<String>();;
String json = [{"GroupPosition":0,"ChildPosition":0},{"GroupPosition":0,"ChildPosition":1},{"GroupPosition":1,"ChildPosition":0}];
JSONArray leagues = new JSONArray(json);
for (int i = 0; i < leagues.length(); i++) {
JSONObject obj = leagues.getJSONObject(i);
array_1.add(obj.getString("GroupPosition"));
}