1

I got the following request from an Android developer:

Would you change the webservice back-end so that it returnes empty strings for empty fields instead of null.

The Android json parser converts null to a string containing "null".

The code:

import com.google.gson.Gson;
//...
private OrganizationSearchResult result;
//...
Gson gson = new Gson();
result = gson.fromJson(resultString, OrganizationSearchResult.class);

Is this a known issue?

If so, is there a known work-around for it?

2
  • 1
    post your code and if have logcat ,post also it Commented Mar 26, 2012 at 9:29
  • I believe your Android developer is mistaken. Android's JSON APIs allow you to detect null and cope with it. Commented Mar 27, 2012 at 1:23

2 Answers 2

2

I dont know what you are using for parsing the json and the JSONObject class in android sdk doesnt do that.

Take a look at the following class

http://developer.android.com/reference/org/json/JSONObject.html

Check out has and isNULL of the above method.

I think GSON automatically handles the null in json by converting them to java null.

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

Comments

0

there will be a method isNull(key) in jsonObject to Determine if the value associated with the key is null or if there is no value, check with this and then call getString(key).

Comments

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.