0

I was trying to get the content from my wordpress website. I wanted the content from the specify post as you can see there: (understanding, this website is not real but it came from real website, I just replace the different title, url, etc.) http://pastebin.com/PWuC8usi

Error said:

Error parsing data Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject

 private void parseJSON(String data){

        try{
            JSONObject jsonResponse = new JSONObject(data);
            //JSONArray jsonMainNode = jsonResponse.getJSONArray("posts");
            JSONArray jsonMainNode = jsonResponse.getJSONArray("content");
            Log.i("App", "jsonMainNode = "+jsonMainNode);

            int jsonArrLength = jsonMainNode.length();
            Log.i("App", "jsonArrLength = "+jsonArrLength);



            for(int i=0; i < jsonArrLength; i++) {

                JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
                String postTitle = jsonChildNode.getString("title");
                String postUrl = jsonChildNode.getString("url");
                String postDate = jsonChildNode.getString("date");
                String postContent = jsonChildNode.getString("content");

                tvPostTitle.setText("Page title: " +postTitle);
                tvPostUrl.setText("Page URL: " +postUrl);
                tvPostDate.setText("Date: " +postDate);
                tvPostContent.setText("Content: " +android.text.Html.fromHtml(postContent).toString());
            }

        }catch(Exception e){
            Log.i("App", "Error parsing data " +e.getMessage());

        }
    }
0

1 Answer 1

1

The program received HTML, not JSON.

This is indicated by the non-JSON text which begins with "<!DOCTYPE..", per the error message.

Only JSON can be parsed as JSON.

In any case the error is elsewhere, perhaps with the request of the data (eg. wrong resource; missing requested type) or perhaps with the server response (eg. not JSON; 40x? 500?). Look at the actual response/data contents and the received HTTP status code for clues.

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

2 Comments

Sorry for late respond, I was busy and happened forgot about ths.
how can I make the program to recieve the HTML but then convert to JSON? I am using the Wordpress API. Restful API.

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.