android-解析来自服务器的JSON响应时出错

android-解析来自服务器的JSON响应时出错,android,json,Android,Json,我会尽量简短,请询问是否有不清楚的地方。我正在从vk.com(一个大型社交网络,以防有人不知道)获取用户的音频列表。答复如下: {"response":[{ "aid":"60830458","owner_id":"6492","artist":"Noname","title":"Bosco", "duration":"195","url":"http:\/\/cs40.vkontakte.ru\/u06492\/audio\/2ce49d2b88.mp3"}, {"aid":

我会尽量简短,请询问是否有不清楚的地方。我正在从vk.com(一个大型社交网络,以防有人不知道)获取用户的音频列表。答复如下:

   {"response":[{
  "aid":"60830458","owner_id":"6492","artist":"Noname","title":"Bosco",
  "duration":"195","url":"http:\/\/cs40.vkontakte.ru\/u06492\/audio\/2ce49d2b88.mp3"},
  {"aid":"59317035","owner_id":"6492","artist":"Mestre Barrao","title":"Sinhazinha",
  "duration":"234","url":"http:\/\/cs510.vkontakte.ru\/u2082836\/audio\/
  d100f76cb84e.mp3"}]}
通常情况下,由于用户的个人资料上可以有数百甚至数千首曲目,所以这段时间要长得多。艺术家和标题也可以包含西里尔字母,这就是我在解析器中使用UTF-8的原因。我对JSON不太熟悉,我尝试使用以下方法解析响应:

 public class JSONParser {

static InputStream is = null;
static JSONObject jObj = null;
static String json = "";


public JSONParser() {

}

public static JSONObject getJSONFromUrl(String url) {


    try {

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();          

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "UTF-8"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }


    return jObj;

}
  }
但应用程序因IllegalArgumentException异常而崩溃(方案中索引为0的非法字符):


知道我做错了什么吗?正确的方法是什么来解析给定格式的响应?有很多应用程序使用相同的API,因此JSON是正确的。。不知道这里出了什么问题

读取JSON时会出现非法参数异常。因为这些URL,所以json无效。另外,对于下一次通信,请将logcat作为文本pls。

您的json无效。谢谢,但正如我提到的,有很多应用程序使用相同的格式,并且可以正常工作。vk支持团队还表示,JSON是正确的,我必须在我这边寻找问题,因为我可以看到问题在url中,在将它们更改为其他字符串后,它将按原样解析JSON。删除图像并将logcat内容作为文本发布我用JSONLint检查了它,似乎问题确实在url中,但是其他vk开发人员说JS和php JSON解析器会自动删除斜杠。。我想我必须手工做这件事。知道怎么做吗?粘贴成文本。还尝试了json=sb.toString();对于(int i=0;i
Try to display the JSON response in JSONlint.com without this url part of :
"url": "http:\/\/cs510.vkontakte.ru\/u2082836\/audio\/
  d100f76cb84e.mp3"

You will find, the response will be validated properly.

I think there is some space characters present in the url part (between audio\/ and d100f76cb84e.mp3) which is coming from response:
"url": "http:\/\/cs510.vkontakte.ru\/u2082836\/audio\/
  d100f76cb84e.mp3"
Try to display the JSON response in JSONlint.com without this url part of :
"url": "http:\/\/cs510.vkontakte.ru\/u2082836\/audio\/
  d100f76cb84e.mp3"

You will find, the response will be validated properly.

I think there is some space characters present in the url part (between audio\/ and d100f76cb84e.mp3) which is coming from response:
"url": "http:\/\/cs510.vkontakte.ru\/u2082836\/audio\/
  d100f76cb84e.mp3"