Java code look likes below; Here I want to get the String to show to in the activity So, Anyone can help me to find the results String from the JSONArray
try {
JSONArray productJsonArray = new JSONArray(result);
int count = productJsonArray.length();
if (count != 0) {
for (int i = 0; i < productJsonArray.length(); i++) {
JSONObject productObject = productJsonArray
.getJSONObject(i);
String pID = productObject.getString("ID");
String pTitle = productObject.getString("title");
String pSDesc = productObject.getString("content");
String pImgSrc = productObject
.getJSONArray("featured_image")
.optJSONObject(0).getString("source");
NewsModel model = new NewsModel();
model.setName(pTitle);
model.setDesc(pSDesc);
model.setId(pID);
model.setImageName(pImgSrc);
newsArrayList.add(model);
}
Here Is the JSON Rsult:
[2]
0: {
ID: 216
title: "New Farcry 4 release"
status: "publish"
modified_gmt: "2014-09-24T07:15:18"
meta: {...}-
featured_image: {
ID: 217
title: "Far-Cry-2-1422"
status: "inherit"
type: "attachment"
author: {...}-
parent: 216
date: "2014-09-24T07:15:14"
modified: "2014-09-24T07:15:14"
format: "standard"
source: "http://www.thusya.com/gamecom/wp-content/uploads/2014/09/Far-Cry-2-1422.jpg"
}-
terms: [0]
}-
Here I have got the exception like below
09-25 19:06:24.308: W/System.err(12575): at org.json.JSON.typeMismatch(JSON.java:111)
09-25 19:06:24.308: W/System.err(12575): at org.json.JSONObject.<init>(JSONObject.java:159)
09-25 19:06:24.308: W/System.err(12575): at org.json.JSONObject.<init>(JSONObject.java:172)
09-25 19:06:24.318: W/System.err(12575): at com.tdzinfo.gamecom.News$GetNews.onPostExecute(News.java:101)
09-25 19:06:24.318: W/System.err(12575): at com.tdzinfo.gamecom.News$GetNews.onPostExecute(News.java:1)
09-25 19:06:24.318: W/System.err(12575): at android.os.AsyncTask.finish(AsyncTask.java:632)
09-25 19:06:24.318: W/System.err(12575): at android.os.AsyncTask.access$600(AsyncTask.java:177)
09-25 19:06:24.318: W/System.err(12575): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
09-25 19:06:24.318: W/System.err(12575): at android.os.Handler.dispatchMessage(Handler.java:102)
09-25 19:06:24.318: W/System.err(12575): at android.os.Looper.loop(Looper.java:157)
09-25 19:06:24.318: W/System.err(12575): at android.app.ActivityThread.main(ActivityThread.java:5335)
09-25 19:06:24.318: W/System.err(12575): at java.lang.reflect.Method.invokeNative(Native Method)
09-25 19:06:24.318: W/System.err(12575): at java.lang.reflect.Method.invoke(Method.java:515)
09-25 19:06:24.318: W/System.err(12575): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
09-25 19:06:24.328: W/System.err(12575): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
09-25 19:06:24.328: W/System.err(12575): at dalvik.system.NativeStart.main(Native Method)
So I want to know how can I handle this to get the Source name from this JSOn Result
0 comments:
Post a Comment