gson.fromJson()方法将无效的json转换为有效的json

时间:2016-07-14 11:19:49

标签: java json web-services rest gson

在我的程序中,我从json格式的rest客户端获取输入并从请求体中检索json我正在使用gson.fromJson方法来检索json。

BufferedReader reader = request.getReader();
JsonElement jsonElement = gson.fromJson( reader , JsonElement.class );

输入json,我传递给休息客户: 它不是一个有效的json。

{
"buildName":FHGF"",
"deadline":"2017-07-28T23:11:15+00:00",
"release":"0.2",
"platformRelease":"5.10.0",
"platformBuild":"1.0.0",
"releatedProducts":"##Product*****",
"expiresInPronto":"2017-07-28T23:11:15+00:00",
"changeNotesRequired":"yes",
"environment":"ah",
"stateTestedInUse":"no"
}

由gson创建的Json:

 {
    **"buildName":"FHGF\"\""**,
    "deadline":"2017-07-28T23:11:15+00:00",
    "release":"0.2",
    "platformRelease":"5.10.0",
    "platformBuild":"1.0.0",
    "releatedProducts":"##Product*****",
    "expiresInPronto":"2017-07-28T23:11:15+00:00",
    "changeNotesRequired":"yes",
    "environment":"ah",
    "stateTestedInUse":"no"
}

而不是抛出错误gson已将其转换为有效的json。

0 个答案:

没有答案