【发布时间】:2019-01-18 18:53:24
【问题描述】:
我有一个 json,其中 1 个键作为 jsonArray 如果它有数据,否则它作为空字符串出现。使用改造在 gson 中解析时出错。
"section": "Technology",
"subsection": "",
"title": "Depiction of Amazon Stirs a Debate About Work Culture",
"abstract": "Details of working conditions at Amazon led to a response from employees, relatives and friends.",
"url": "http://www.nytimes.com/2015/08/19/technology/amazon-workplace-reactions-comments.html",
"byline": "By THE NEW YORK TIMES",
"item_type": "Article",
"updated_date": "2015-08-18T07:35:33-5:00",
"created_date": "2015-08-18T07:35:35-5:00",
"published_date": "2015-08-19T04:00:00-5:00",
"material_type_facet": "News",
"kicker": "",
"des_facet": [
"Workplace Environment"
],
"org_facet": [
"Amazon.com Inc"
],
"per_facet": "",
"geo_facet": "",
des_facet, org_facet, per_facet, geo_facet 是 jsonArray 但你可以看到 2 没有数据所以以空字符串的形式出现。
如何使用改造 +gson 来处理这种情况。
无法在服务器上更改 JSON 格式。
有什么方法可以在android中实现吗?
【问题讨论】:
-
您想在设置数据为空或为空时处理?
-
@AkshayKatariya :我从服务器收到此响应,我需要使用改造和 gson 在 android 中解析它。
-
您使用的是自定义解析还是
GsonConverterFactory? -
当您使用 Retrofit 时,您的响应应该有一种格式。它应该始终是一个数组。
-
@AkshayKatariya:是的,我正在使用 GsonConverterFactory