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());
}
}