格式化包含Android Java

时间:2017-06-13 07:47:24

标签: java android json

我在android asyn调用中使用了一个rest方法,json对象示例在下面 -

“结果”:1,     “数据”:[{         “id”:1,         “名字”:“乌头”,         “url”:“http://i1.wp.com/cottagegardenflowershop.co.uk/wp-content/uploads/2014”     }

我想格式化如下的网址 - http://i1.wp.com/cottagegardenflowershop.co.uk/wp-content/uploads/2014

1 个答案:

答案 0 :(得分:0)

这里用这个: 假设你收到你的Json内部响应字符串

String response = "result": 1, "data": [{ "id": 1, "name": "Aconitum", "url": "http://i1.wp.com/cottagegardenflowershop.co.uk/wp-content/uploads/2014" } 
JSONArray data = response.optJSONArray("data");
for (int i =0;i<data.length();i++){
 JSONObject jsonObject = data.getJSONObject(i);
//save this url in a list or however you want to use it
    String url = jsonObject.getString("url");
}