Skip to content Skip to sidebar Skip to footer

How To Get The Result For Return Statement From Json Parsing?

I've follow the code for parsing the value with JSON from here, but I get the problem in my return statement. I want to put the parsing result into my return statement. How to do t

Solution 1:

If you have JSON array object:

JSONObject jObject = newJSONObject(***JSONString you have ***);
JSONArray contestantObjects = jObject.getJSONArray("*** Array Name ***");
for(int i=0; i<contestantObjects.length(); i++) {
        mChannels.setId(contestantObjects.getJSONObject(i).getString("id").toString());
        mChannels.setName(contestantObjects.getJSONObject(i).getString("name").toString());
}

If you have just one item:

JSONObject jObject = newJSONObject(***JSONString you have ***);
mPreview.setBody(jObject.getString("*** Item Name ***").toString());
mPreview.setPublishedDate(jObject.getString("publishedDate").toString());
mPreview.setRefKey(jObject.getString("refKey").toString());
mPreview.setTitle(jObject.getString("title").toString());

http://jsonviewer.stack.hu/ is online tool for parsing JSON. its awesome you can use it.

Solution 2:

JSONObject prefsJson = newJSONObject(prefsJsonString);
String str = prefsJson.has("str") == true ? prefsJson.getString("str") : "";

Is that ok?

Solution 3:

Referring to the link which you have used to parse the JSON String, I would suggest that you return the object bundleResult from your function. Change the return value for your method as public Bundle MASUK(String user, String password).

EDIT

Don't forget to initialize the Bundle object:

private Bundle bundleResult=newBundle();

And take care not to change the case (upper/lower case) for the variable being used. I could see in your code BundleResult.putString(Key, Value); and the reference link uses bundleResult.putString(Key, Value);

Post a Comment for "How To Get The Result For Return Statement From Json Parsing?"