JSON 字符串数组(无对象),提取数据 [英] JSON Array of strings (no objects), extracting data
问题描述
我有一个很长的 JSON 字符串,表示从 WCF 服务返回的 string[] 数组.数组元素只是字符串,它们不是对象.这是返回数据的示例
I have a long JSON string representing a string[] array being returned from a WCF service. The array elements are simply strings, they are not objects. This is an example of the return data
["1|ArrayElement1","2|ArrayElement2","3|ArrayElement3"..."n|ArrayElementn"]
我不介意包含在字符串中的索引,但我需要在 Android 中将字符串解析为 ArrayList,以便我可以将其调整为 ListView.
I don't mind the index being included in the string, but I need to parse the strings into an ArrayList in Android so that I can adapt it to a ListView.
由于这些在技术上不是 JSONObjects,我如何遍历它们并从每个数组元素中提取字符串?
Since these technically aren't JSONObjects, how can I iterate over them and extract the string from each array element?
推荐答案
这是一个有效的 JSON 字符串数组,你可以像这样正常解析它
this is a valid JSON array of strings, you can parse it normally like this
JSONArray jsonStrings = json.getJSONArray("items");
String strings[] = new String[jsonStrings.length()];
for(int i=0;i<strings.length;i++) {
strings[i] = jsonStrings.getString(i);
}
这篇关于JSON 字符串数组(无对象),提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!