冒号(:)内JSON数据使用GSON [英] colon (:) within JSON data using Gson

查看:1454
本文介绍了冒号(:)内JSON数据使用GSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打电话,返回JSON的Web服务。内JSON我有一个持有URL的属性。但是,冒号(:)该网址中正在GSON抛出一个 gson.stream.MalformedJsonException 错误。我知道这些键和值应包装

I'm calling a web service that returns JSON. Within that JSON I have a property that holds a URL. But the colon (:) within that URL is making Gson throw a gson.stream.MalformedJsonException error. I know these keys and values should be wrapped

{
   ID=15; 
   Code=ZPFgNr; 
   UserName=https://www.google.com/accounts/o8/id?id=xxxxxx; //<--problem
   FirstName=Joe
}

我的Java:

resultData=((SoapObject) result).getProperty(0).toString();
User response = gson.fromJson(resultData, User.class);

我知道这些键和值应该用双引号括起来。但是他们都没有了,这似乎是这个问题。

I know these keys and values should be wrapped in double quotes. But they are not, and that seems to be the problem.

我应该以某种方式反序列化之前编码此JSON?如果是这样,怎么样?

Should I be encoding this JSON before deserializing it somehow? If so, how?

我应该做一个查找和替换 HTTPS:和逃避冒号,如果是的话,我将如何逃脱结肠

Should I do a find and replace on https: and escape the colon, If so, how would I escape the colon?

推荐答案

JSON使用逗号分隔的属性,冒号属性名称从属性值,和周围的名称双引号和分隔值。这不是有效的JSON。

JSON uses commas to separate attributes, colon to separate the attribute name from the attribute value, and double quotes around the names and the values. This is not valid JSON.

下面是有效的JSON:

Here's valid JSON:

{
   "ID" : "15", 
   "Code" : "ZPFgNr",
   "UserName" : "https://www.google.com/accounts/o8/id?id=xxxxxx",
   "FirstName" : "Joe"
}

这篇关于冒号(:)内JSON数据使用GSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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