2016-04-20 8 views
0

i in Abrufen von spezifischen Daten vom Server ahave Problem umgewandelt wird dies mein Code ist irgendeine beliebige idea` hatjava.lang.String kann nicht auf JSONObject

enter code herepublic String URL_ITEMS = "http://getdoctor.comlu.com/aa.php?name=Naveed"; 
private static final String TAG_FIXTURE = "checker"; 
private static final String TAG_MATCHID = "dphone"; 
private static final String TAG_TEAMA = "pphone"; 

das ist `Josn Code Code hier private Klasse GetFixture eingeben AsyncTask erstreckt {

@Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 
    } 
    @Override 
    protected Void doInBackground(Void... arg) { 


     ServiceHandler serviceClient = new ServiceHandler(); 
     Log.d("url: ", "> " + URL_ITEMS); 
     String json = serviceClient.makeServiceCall(URL_ITEMS,ServiceHandler.GET); 
     // print the json response in the log 
     Log.d("Get match fixture resps","> " + json); 
     if (json != null) { 
      try { 
       Log.d("try", "in the try"); 
       JSONObject jsonObj = new JSONObject(json); 
       Log.d("jsonObject", "new json Object"); 
       // Getting JSON Array node 
       matchFixture = jsonObj.getJSONArray(TAG_FIXTURE); 
       Log.d("json aray", "user point array"); 
       int len = matchFixture.length(); 
       Log.d("len", "get array length"); 
       for (int i = 0; i < matchFixture.length(); i++) { 
        JSONObject c = matchFixture.getJSONObject(i); 
        String matchId = c.getString(TAG_MATCHID); 
        Log.d("matchId", matchId); 
        String teamA = c.getString(TAG_TEAMA); 
        Log.d("teamA", teamA); 

        // hashmap for single match 
        HashMap<String, String> matchFixture = new HashMap<String, String>(); 
        // adding each child node to HashMap key => value 
        matchFixture.put(TAG_MATCHID, matchId); 
        matchFixture.put(TAG_TEAMA, teamA); 

        matchFixtureList.add(matchFixture); 
       } 
      } 
      catch (JSONException e) { 
       Log.d("catch", "in the catch"); 
       e.printStackTrace(); 
      } 
     } else { 
      Log.e("JSON Data", "Didn't receive any data from server!"); 
     } 
     return null; 
    }' 

und dies ist mein logcat jeder Körper eine Ahnung, warum ich erhalte diesen Fehler

enter code hereD/url:: > http://getdoctor.comlu.com/aa.php?name=Naveed 
04-20 13:12:33.6-32287/com.example.finddoctor D/Get match fixture resps: > Naveed{"checker":[{"pphone":""},{"pphone":"1"},{"pphone":"1"},{"pphone":"5415"},{"pphone":"5415"},{"pphone":"5415"}]} 
04-20 13:12:33.6-32287/com.example.finddoctor D/try: in the try 
04-20 13:12:33.6-32287/com.example.finddoctor D/catch: in the catch 
04-20 13:12:33.6-32287/com.example.finddoctor W/System.err: org.json.JSONException: Value Naveed of type java.lang.String cannot be converted to JSONObject 
04-20 13:12:33.6-32287/com.example.finddoctor W/System.err:  at org.json.JSON.typeMismatch(JSON.java:107) 
04-20 13:12:33.6-32287/com.example.finddoctor W/System.err:  at org.json.JSONObject.<init>(JSONObject.java:158) 
04-20 13:12:33.6-32287/com.example.finddoctor W/System.err:  at org.json.JSONObject.<init>(JSONObject.java:171) 
04-20 13:12:33.6-32287/com.example.finddoctor W/System.err:  at com.example.finddoctor.Doctor_notification$GetFixture.doInBackground(Doctor_notification.java:199) 
04-20 13:12:33.6-32287/com.example.finddoctor W/System.err:  at com.example.finddoctor.Doctor_notification$GetFixture.doInBackground(Doctor_notification.java:181) 
04-20 13:12:33.6-32287/com.example.finddoctor W/System.err:  at android.os.AsyncTask$2.call(AsyncTask.java:185) 
04-20 13:12:33.6-32287/com.example.finddoctor W/System.err:  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) 
04-20 13:12:33.6-32287/com.example.finddoctor W/System.err:  at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
04-20 13:12:33.6-32287/com.example.finddoctor W/System.err:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 
04-20 13:12:33.6-32287/com.example.finddoctor W/System.err:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 
04-20 13:12:33.6-32287/com.example.finddoctor W/System.err:  at java.lang.Thread.run(Thread.java:1019)` 
+0

vielleicht wegen Naveed { "Checker": [{ "pphone": ""}, { "pphone": "1"}, { "pphone" : "1"}, {"phone": "5415"}, {"phone": "5415"}, {"phone": "5415"}]} JSONObject sollte mit {} – user3280437

+0

verbunden sein, also Sir, was sollte Ich mache es –

+0

entfernen führenden Naveed von der Antwort – user3280437

Antwort

2

Es scheint, von der Linie

Log.d("Get match fixture resps","> " + json); 

und von logcat

Get Matchansetzung RESPS:> Naveed { "Checker": [{ "pphone": ""}, { "pphone":“ 1 "}, {" phone ":" 1 "}, {" phone ":" 5415 "}, {" phone ":" 5415 "}, {" phone ":" 5415 "}]}

Ihr JSON

Naveed{"checker":[{"pphone":""},{"pphone":"1"},{"pphone":"1"},{"pphone":"5415"},{"pphone":"5415"},{"pphone":"5415"}]} 

ist InValid. Entfernen Sie Naveed von it.i.e. die gültige Json wäre

{"checker":[{"pphone":""},{"pphone":"1"},{"pphone":"1"},{"pphone":"5415"},{"pphone":"5415"},{"pphone":"5415"}]} 

Sie es auf http://jsonlint.com/ überprüfen können

1

Sie folgende Antwort bekommen, die nicht richtige json ist.

Naveed{"checker":[{"pphone":""},{"pphone":"1"},{"pphone":"1"},{"pphone":"5415"},{"pphone":"5415"},{"pphone":"5415"}]} 

Notwendigkeit Antwort wie diese

{"checker":[{"pphone":""},{"pphone":"1"},{"pphone":"1"},{"pphone":"5415"},{"pphone":"5415"},{"pphone":"5415"}]} 
Verwandte Themen