android - JSON 字符串数组(无对象),提取数据

标签 android json android-listview arrays

我有一个很长的 JSON 字符串,表示从 WCF 服务返回的 string[] 数组。数组元素只是字符串,它们不是对象。这是返回数据的例子

    ["1|ArrayElement1","2|ArrayElement2","3|ArrayElement3"..."n|ArrayElementn"]

我不介意字符串中包含索引,但我需要将字符串解析为 Android 中的 ArrayList,以便我可以将其适配为 ListView。

由于这些在技术上不是 JSONObject,我如何遍历它们并从每个数组元素中提取字符串?

最佳答案

这是一个有效的JSON字符串数组,你可以像这样正常解析它

JSONArray jsonStrings = json.getJSONArray("items");
String strings[] = new String[jsonStrings.length()];
for(int i=0;i<strings.length;i++) {
strings[i] = jsonStrings.getString(i);
}

关于android - JSON 字符串数组(无对象),提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10147851/

相关文章:

android - java.lang.IllegalStateException : Not connected. 调用connect()并等待onConnected()被调用

android - 在Android中缓存媒体对象

java - Android排序数组

android - 刷新同一 Activity 中剩余的当前 fragment (ListView 数据)

android - ListView 中的硬件加速

java - 生成具有列表和字符串类型属性的 JSON 模型

c++ - 用boost读取json文件

Python排序方法将两位数字字符串视为三位数字字符串

javascript - 如何使 Codeschools 的 Angular 边看起来相似?

java - 如何从 Edittext 在自定义 ListView 中显示值