org.json.JSONException: Kein Wert für die Kommentare

Habe ich eine Json-Daten, die ich erhalte aus einem wordpress-blog, und als ich versuchte Weitergabe der url bekomme ich diesen Fehler in meinem logcat sagen org.json.JSONException: Kein Wert für die Kommentare.

was versuche zu tun, ist das abrufen Kommentare aus einem wordpress-blog.

Ich eingefügt haben meinen vollen code hier für weitere Referenzen,

03-13 11:43:59.698: W/System.err(18926): org.json.JSONException: No value for comments
03-13 11:43:59.698: W/System.err(18926):    at org.json.JSONObject.get(JSONObject.java:354)
03-13 11:43:59.698: W/System.err(18926):    at org.json.JSONObject.getJSONArray(JSONObject.java:544)
03-13 11:43:59.698: W/System.err(18926):    at com.cepfmobileapp.org.CommentActivityWp$GetQuery.doInBackground(CommentActivityWp.java:271)
03-13 11:43:59.698: W/System.err(18926):    at com.cepfmobileapp.org.CommentActivityWp$GetQuery.doInBackground(CommentActivityWp.java:1)
03-13 11:43:59.698: W/System.err(18926):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-13 11:43:59.698: W/System.err(18926):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-13 11:43:59.698: W/System.err(18926):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-13 11:43:59.708: W/System.err(18926):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-13 11:43:59.708: W/System.err(18926):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
03-13 11:43:59.708: W/System.err(18926):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
03-13 11:43:59.708: W/System.err(18926):    at java.lang.Thread.run(Thread.java:856)

Java-Code

    private static final String TAG_COMMENTS = "comments";
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
private static final String TAG_CONTENT = "content";


    Intent i = getIntent();
    //Receiving the Data
    ida = i.getStringExtra("id");
    url = "" + ida;


    @Override
    protected Void doInBackground(Void... arg0) {
        //Creating service handler class instance
        ServiceHandler sh = new ServiceHandler();

        //Making a request to url and getting response
        String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);

        Log.d("Response: ", "> " + jsonStr);

        if (jsonStr != null) {
            try {
                JSONObject jsonObj = new JSONObject(jsonStr);

                //Getting JSON Array node
                comments = jsonObj.getJSONArray(TAG_COMMENTS);

                //looping through All Contacts
                for (int i = 0; i < comments.length(); i++) {
                    JSONObject c = comments.getJSONObject(i);


                    //Phone node is JSON Object
                     //JSONObject comments = c.getJSONObject(TAG_COMMENTS );
                     String id = c.getString(TAG_ID);
                     String name = c.getString(TAG_NAME);
                     String content = c.getString(TAG_CONTENT);

                    //tmp hashmap for single contact
                    HashMap<String, String> contact = new HashMap<String, String>();

                    //adding each child node to HashMap key => value
                    contact.put(TAG_ID, id);
                    contact.put(TAG_NAME, name);
                    contact.put(TAG_CONTENT, content);


                    //adding contact to contact list
                    queryList.add(contact);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else {
            Log.e("ServiceHandler", "Couldn't get any data from the url");
        }

        return null;
    }
  • Hast du überprüft Ihre Reaktion ?
  • Ihre comments array befindet sich unter Ihrem posts arraylist, so haben Sie es von der posts arraylist nur.
  • ja, es wurden keine Daten angezeigt und dann bekam ich diesen Kommentar in meinem logcat sagen, org.json.JSONException: Kein Wert für die Kommentare
  • können Sie mir zeigen, wie gehen über diese
  • Können Sie Ihre Antwort-format ?
  • Überprüfen Sie heraus meine Antwort @m.opeyemi

InformationsquelleAutor | 2014-03-13
Schreibe einen Kommentar