安卓:解析使用GSON'空'值JSON [英] Android: parsing json with 'null' values using Gson

查看:214
本文介绍了安卓:解析使用GSON'空'值JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 Android开发者提出以下要求

你会改变web服务后端,这样它的 returnes空
  字符串
作为空字段的而不是空

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

Android的JSON 解析器转换为null 包含字符串

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

在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?

推荐答案

我不知道你用的是什么了解析JSON和Android SDK中犯规的JSONObject的类做到这一点。

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

在下面的类看看

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

看看 ISNULL 上述方法的。

我觉得GSON将它们转换成Java空自动处理JSON空。

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

这篇关于安卓:解析使用GSON'空'值JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆