Json中的Android类型不匹配错误

时间:2016-11-13 12:59:22

标签: android json

**我认为我在将JET请求传递给youtube以获取JSON列表时面临问题

** public class GetYouTubeUserVideosTask实现Runnable {

public static final String LIBRARY = "Library";
private final Handler replyTo;
private final String username;
 public HttpUriRequest request;
public GetYouTubeUserVideosTask(Handler replyTo, String username) {
    this.replyTo = replyTo;
    this.username = username;
}

@Override
public void run() {
    try {
        HttpClient client = new DefaultHttpClient();
        HttpUriRequest request = new HttpGet("https://gdata.youtube.com/feeds/api/videos?author=" +username+"PL25zD6TOnoFVKHbBRCaUfkgS00d1It2h9");
        HttpResponse response = null;
        response = client.execute(request);
        String jsonString = StreamUtils.convertToString(response.getEntity().getContent());
        JSONObject json = new JSONObject(jsonString);
        JSONObject response1 = json.getJSONObject("response");
        JSONArray jsonArray = response1.getJSONArray("items");
        List<Video> videos = new ArrayList<Video>();
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            String title = jsonObject.getString("title");
            Log.i("...........",title);
            String url;
            try {
                url = jsonObject.getJSONObject("player").getString("mobile");
            } catch (JSONException ignore) {
                url = jsonObject.getJSONObject("player").getString("default");
            }
            String thumbUrl = jsonObject.getJSONObject("thumbnail").getString("sqDefault");
            videos.add(new Video(title, url, thumbUrl));
        }
        Library lib = new Library(username, videos);
        Bundle data = new Bundle();
        data.putSerializable(LIBRARY, lib);
        Message msg = Message.obtain();
        msg.setData(data);
        replyTo.sendMessage(msg);
    }  catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    } catch (JSONException e2) {
        e2.printStackTrace();

    } 

我是Android的新手,我正在尝试解析JSON但是遇到类型不匹配错误。请帮帮我。

我不知道我哪里出错了。我的logcat是

  

11-12 07:45:59.953 27498-28258 / com.example.titus.abc   W / System.err:org.json.JSONException:Value(JSONObject.java:159)11-12 07:45:59.953   27498-28258 / com.example.titus.abc W / System.err:at   org.json.JSONObject。(JSONObject.java:172)11-12 07:45:59.953   27498-28258 / com.example.titus.abc W / System.err:at   com.example.titus.abc.GetYouTubeUserVideosTask.run(GetYouTubeUserVideosTask.java:48)

0 个答案:

没有答案