I need to get one JSON value, but it is not working. I can already read the json data but I cannot add to the list and read just one or two values
{
"item": [
{
"gallery": "user_files/goods/sOOsUcrM2Xorb3fbaD9bVoK9wDKDkmEjeKKZrJC7.jpeg, user_files/goods/Csc9XgxKUEkdI3jts7f2gV22hPqAKh5cJGYkvf7k.jpeg"
}}
JSONArray jsonArray = response.getJSONArray("result");
for(int i = 0 ; i < jsonArray.length();i++)
{
JSONObject m = jsonArray.getJSONObject(i);
String gallery = m.getString("gallery");
urls.add(gallery);
}
Toast.makeText(getActivity(),urls.get(0),Toast.LENGTH_LONG).show();
首先,它是在Android或任何平台上读取的错误JSON格式,因为coma( ,
)永远无法分离JSON数据...而且,如果要使用它,请遵循如何拆分逗号分隔的字符串?
As I Understand,you need one value only from multiple values.
you should try this.
JSONArray jsonArray = response.getJSONArray("result");
for(int i = 0 ; i < jsonArray.length();i++)
{
JSONObject m = jsonArray.getJSONObject(i);
String gallery = m.getString("gallery");
String[] array=gallery.split(",");
// array[0]; contains 1st value
// array[1]; contains 2nd value
urls.add(gallery);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.