I'm calling a web service from my Android application. The web service returns the following JSON :
Now the problem is when I'm trying to get the description element of the record object I'm getting an exception as org.json.JSONException: No value for description
Now my question is how can I get the value of the description using the existing parser without changing the response JSON format.
According to me,
You are using the wrong object to get description value otherwise org.json.JSONException: No value for description error will not occur.
Also, check if you can using optString instead of getString which just returns null if value do not exist, instead of throwing an exception.
Related
I am getting JSON Response which have a key studentScore.
First time it comes studentScore="102" and,
Second time it comes like studentScore = 101.
So, My Question is how Can I detect every time which type of value is coming?
for example integer or string.
so, how can i figure out about this in android using JsonObjects?
When we change URL to incorrect value then we get HTML type response from server side that we restore in hamhMap key value on the basis of "=". The hashMap key contain HTML tags like
"<html>\t<head>\t\t<title>CSRFRedirect</title>\t</head>\t<body>\t\t\t\t<form method"
Please guide how to handle this type of key?
check the response code of your api response. if it throws error code 500 it is server error , you can handle it
check here for more info
previously json null was handling properly in app. But suddenly app failed to parse son, as it found NULL instead of null. I want to know, if "NULL" is valid null json object, in any of the json library used for android.
Here is some info .
First of all null is keyword in JAVA for indicating object is empty(null).
NULL is not keyword in JAVA
NULL is valid value for string if it is enclosed by "". eg "NULL"
I want to know, if "NULL" is valid null json object, in any of the
json library used for android.
Answer is NO.
Yes,NULL is object in android,added in API level 1.
See the below image,This is screen shot of android studio documentation.
I am developing an android application and i need to parse the json data from YQL
https://query.yahooapis.com/v1/public/yql?q=select%20%20*%20from%20%20yahoo.finance.historicaldata%20where%20symbol%20in%20(%27YHOO%27)%20and%20startDate%20%3D%20%272016-01-01%27%20and%20endDate%20%3D%20%272016-04-10%27&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=
I am using JsonReader to access the Count and the Result object. The problem am facing is how do I check the object name and then call beginobject on results object . I am able to fetch the counts value though from the Json Feed
I am reading some inforamtion from database as json object .
the database returns a well formated string ( as json object ) .
When i try to convert the string to jsonObject .. it returns null
here is the string from database :
{"items":[{"title":"Police","icon":"police","type":"normal","tel":"999"},{"title":"Ambulance","icon":"ambulance","type":"normal","tel":"976"},{"title":"Electricity","icon":"electricity","type":"normal","tel":"4848"},{"title":"Fire Station","icon":"fire","type":"normal","tel":"998"},{"title":"Airport Information 1","icon":"airport","type":"normal","tel":"0183447405"},{"title":"Airport Information 2","icon":"airport","type":"normal","tel":"0183780129"},{"title":"Water","icon":"water","type":"normal","tel":"3131"}],"success":1}
and here the response error from logcat :
12-18 20:24:44.529: W/System.err(25062): org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject
as you can see it indicate that the string value is empty ... while the logcat shows me my string ....
Please note that this code was working very well before ..
EDIT :
I tried the same code to read from different database . and it worked well
i guess its database error .