0

我想从 Json 中获取文本(一些 url)并将它们直接添加到String[]android 中。文字就像

"http://www.androiddrawer.com/wp-content/uploads/2013/05/Subway-Surfers-screenshot-4-1.png","http://www.androiddrawer.com/wp-content/uploads/2013/05/Subway-Surfers-screenshot-4-2.png","http://www.androiddrawer.com/wp-content/uploads/2013/05/Subway-Surfers-screenshot-4-3.png","http://www.androiddrawer.com/wp-content/uploads/2013/05/Subway-Surfers-screenshot-4-4.png"

我想将此文本放入 String[] 中。我知道我可以使用这种方法:

products = json.getJSONArray(TAG_PRODUCTS);
JSONObject c = products.getJSONObject(0);
String name = c.getString(TAG_NAME);

但它给了我字符串而不是字符串 []。

4

2 回答 2

3

通过查看您的字符串

"http://www.androiddrawer.com/wp-content/uploads/2013/05/Subway-Surfers-screenshot-4-1.png","http://www.androiddrawer.com/wp-content/uploads/2013/05/Subway-Surfers-screenshot-4-2.png","http://www.androiddrawer.com/wp-content/uploads/2013/05/Subway-Surfers-screenshot-4-3.png","http://www.androiddrawer.com/wp-content/uploads/2013/05/Subway-Surfers-screenshot-4-4.png" 

这似乎可以转换成String[]。

使用喜欢

String[] result = above_string_variable.split(",");

在你的情况下

利用

String[] result = c.getString(TAG_NAME).split(",");

代替

String name = c.getString(TAG_NAME);
于 2013-05-23T06:51:49.103 回答
0
products = json.getJSONArray(TAG_PRODUCTS);
String[] result = new String[products.length()];
for(int i=0;i<products.length();i++) {

JSONObject c = products.getJSONObject(i);
    result[i] = c.getString(TAG_NAME);
}
于 2013-05-23T06:58:27.833 回答