JSON字符串数组(无对象),提取数据 [英] JSON Array of strings (no objects), extracting data
问题描述
我有很长的JSON字符串重新presenting一个String []数组从WCF服务返回。数组元素是简单的字符串,它们不是对象。这是返回数据的一个例子
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屋!