2013-12-09 3 views
0

나는 newbaby android이고 발리에 대해 몇 가지 연습을합니다.안드로이드에서 발리 던지기 JsonPars 예외

RequestQueue rq = Volley.newRequestQueue(this); 
    String urlStr="https://api.github.com/users/mralexgray/repos"; 
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
      com.android.volley.Request.Method.GET,urlStr, null, 
      new Response.Listener<JSONObject>() { 

       @Override 
       public void onResponse(JSONObject response) { 

        Log.d("Response", response.toString()); 
       } 
      }, new Response.ErrorListener() { 

       @Override 
       public void onErrorResponse(VolleyError error) { 
        // TODO Auto-generated method stub 
        Toast.makeText(MainActivity.this, error.toString(), 
          Toast.LENGTH_LONG).show(); 
        Log.d("Error!!!!", error.toString()); 
       } 
      }); 
    rq.add(jsonObjectRequest); 

그러나 프로그램 던지는 예외 :

com.android.volley.ParseError: org.json.JSONException: Value [{"has_issues":true,"teams_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/teams","releases_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/releases{\/id}","compare_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/compare\/{base}...{head}","keys_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/keys{\/key_id}","milestones_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/milestones{\/number}","description":null,"has_wiki":true,"events_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/events","archive_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/{archive_format}{\/ref}","subscribers_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/subscribers","contributors_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/contributors","pushed_at":"2012-10-06T16:37:39Z","fork":false,"svn_url":"https:\/\/github.com\/mralexgray\/-REPONAME","collaborators_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/collaborators{\/collaborator}","subscription_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/subscription","clone_url":"https:\/\/github.com\/mralexgray\/-REPONAME.git","trees_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/git\/trees{\/sha}","homepage":null,"url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME","size":76,"notifications_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/notifications{?since,all,participating}","updated_at":"2013-01-12T13:39:30Z","branches_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/branches{\/branch}","owner":{"received_events_url":"https:\/\/api.github.com\/users\/mralexgray\/received_events","organizations_url":"https:\/\/api.github.com\/users\/mralexgray\/orgs","avatar_url":"https:\/\/0.gravatar.com\/avatar\/50e7ed4eb2e7af000ea7d161748958f1?d=https%3A%2F%2Fidenticons.github.com%2F27bbb5393e06a225e4ecf9c4ce6feabf.png&r=x","gravatar_id":"50e7ed4eb2e7af000ea7d161748958f1","gists_url":"https:\/\/api.github.com\/users\/mralexgray\/gists{\/gist_id}","starred_url":"https:\/\/api.github.com\/users\/mralexgray\/starred{\/owner}{\/repo}","site_admin":false,"type":"User","url":"https:\/\/api.github.com\/users\/mralexgray","html_url":"https:\/\/github.com\/mralexgray","id":262517,"following_url":"https:\/\/api.github.com\/users\/mralexgray\/following{\/other_user}","events_url":"https:\/\/api.github.com\/users\/mralexgray\/events{\/privacy}","login":"mralexgray","subscriptions_url":"https:\/\/api.github.com\/users\/mralexgray\/subscriptions","repos_url":"https:\/\/api.github.com\/users\/mralexgray\/repos","followers_url":"https:\/\/api.github.com\/users\/mralexgray\/followers"},"issue_events_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/issues\/events{\/number}","language":null,"forks_count":0,"contents_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/contents\/{+path}","watchers_count":0,"blobs_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/git\/blobs{\/sha}","commits_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/commits{\/sha}","has_downloads":true,"git_commits_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/git\/commits{\/sha}","private":false,"open_issues":0,"id":6104546,"downloads_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/downloads","mirror_url":null,"comments_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/comments{\/number}","name":"-REPONAME","created_at":"2012-10-06T16:37:39Z","stargazers_count":0,"assignees_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/assignees{\/user}","pulls_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/pulls{\/number}","watchers":0,"stargazers_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/stargazers","hooks_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/hooks","languages_url":"https:\/\/api.github.com\/repos\/mralexgray\/-REPONAME\/la 

가 어떻게이 오류를 해결 할 수 있습니다 나는 샘플 코드를 작성?

+1

당신이 JsonArray 아닌 된 JSONObject이다 게시 된 JSON의 일부를 도움이 될 것입니다 다음과 같이 JSON 배열을 JSON 개체 그래서 발리 요청 방법을 수정하지 않습니다 우선. 또한 JSONObject와 JsonObject 클래스가 섞여있는 것처럼 보입니다. JSONObject와 JsonObject 클래스는 동일한 문제가 아니기 때문에 문제를 일으킬 수 있습니다. 내가 어디에서 오류가 발생했는지 정확히 알 수는 없지만 실패 할 수도있는 곳을보고 전체 스탁 추적을 게시하지 않았지만 응답이 배열이고 org를 혼합하지 않는 경우 JsonArray를 요청하십시오. json 및 com.google.gson 클래스. – Turnsole

답변

1

응답은,

RequestQueue rq = Volley.newRequestQueue(this); 
    String urlStr = "https://api.github.com/users/mralexgray/repos"; 
    JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(urlStr, 
      new Response.Listener<JSONArray>() { 

       @Override 
       public void onResponse(JSONArray response) { 
        // TODO Auto-generated method stub 
        Log.d("Response", response.toString()); 
       } 

      }, new Response.ErrorListener() { 

       @Override 
       public void onErrorResponse(VolleyError error) { 
        // TODO Auto-generated method stub 
        Toast.makeText(MainActivity.this, error.toString(), 
           Toast.LENGTH_LONG).show(); 
         Log.d("Error!!!!", error.toString()); 
       } 
      }); 
    rq.add(jsonArrayRequest); 

이 당신에게