0

i ahave problem in retrieving specific data from server this is my code any one have any idea`

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";

this is Josn code `enter code here private class GetFixture extends AsyncTask {

    @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;
    }'

and this is my logcat any body have any idea why i am getting this error

enter code hereD/url:: > http://getdoctor.comlu.com/aa.php?name=Naveed
04-20 13:12:33.901 32106-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.901 32106-32287/com.example.finddoctor D/try: in the try
04-20 13:12:33.911 32106-32287/com.example.finddoctor D/catch: in the catch
04-20 13:12:33.911 32106-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.911 32106-32287/com.example.finddoctor W/System.err:     at org.json.JSON.typeMismatch(JSON.java:107)
04-20 13:12:33.911 32106-32287/com.example.finddoctor W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:158)
04-20 13:12:33.921 32106-32287/com.example.finddoctor W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:171)
04-20 13:12:33.921 32106-32287/com.example.finddoctor W/System.err:     at com.example.finddoctor.Doctor_notification$GetFixture.doInBackground(Doctor_notification.java:199)
04-20 13:12:33.921 32106-32287/com.example.finddoctor W/System.err:     at com.example.finddoctor.Doctor_notification$GetFixture.doInBackground(Doctor_notification.java:181)
04-20 13:12:33.921 32106-32287/com.example.finddoctor W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-20 13:12:33.921 32106-32287/com.example.finddoctor W/System.err:     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
04-20 13:12:33.921 32106-32287/com.example.finddoctor W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
04-20 13:12:33.921 32106-32287/com.example.finddoctor W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
04-20 13:12:33.931 32106-32287/com.example.finddoctor W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
04-20 13:12:33.931 32106-32287/com.example.finddoctor W/System.err:     at java.lang.Thread.run(Thread.java:1019)`
3
  • maybe because of Naveed{"checker":[{"pphone":""},{"pphone":"1"},{"pphone":"1"},{"pphone":"5415"},{"pphone":"5415"},{"pphone":"5415"}]} JSONObject shoult be bound with {} Commented Apr 20, 2016 at 8:25
  • so sir what should i do for it Commented Apr 20, 2016 at 8:31
  • remove leading Naveed from response Commented Apr 20, 2016 at 8:32

2 Answers 2

2

It seems from line

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

and from logcat

Get match fixture resps: > Naveed{"checker":[{"pphone":""},{"pphone":"1"},{"pphone":"1"},{"pphone":"5415"},{"pphone":"5415"},{"pphone":"5415"}]}

your json

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

is InValid. Remove Naveed from it.i.e. the valid json would be

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

You may check it on http://jsonlint.com/

Sign up to request clarification or add additional context in comments.

Comments

1

you are getting following response which is not proper json.

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

need response like this

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.