0

**I think I am facing problem on passing GET request to youtube for JSON list

**public class GetYouTubeUserVideosTask implements 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();

    } 

I am new to android and I am trying to parse JSON but getting type mismatch error. please help me out.

I don't know where I am getting wrong. My logcat is

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)

Ensign
  • 19
  • 1
  • 2
    http://stackoverflow.com/questions/10876079/org-json-jsonexception-value-doctype-of-type-java-lang-string-cannot-be-conve http://stackoverflow.com/questions/19872822/jsonexception-value-doctype-of-type-java-lang-cannot-be-converted-to-jsonobje http://stackoverflow.com/questions/18682046/android-error-org-json-jsonexception-value-doctype-of-type-java-lang-string-c http://stackoverflow.com/questions/30800107/doctype-of-type-java-lang-string-cannot-be-converted-to-jsonobject – Mike M. Nov 13 '16 at 13:07
  • Looks at [this](http://stackoverflow.com/questions/36230822/parsejson-java-parsing-result-if-no-array-name/36247090#36247090) link – Mahendra Gunawardena Nov 13 '16 at 13:37
  • @MahendraGunawardena i think i am facing problem on passing GET request to YouTube for a JSON list. please help me friend i strucked here. – Ensign Nov 14 '16 at 09:37

0 Answers0