简体   繁体   English

Google应用程式引擎中的Json

[英]Json in Google app engine

In my project i have to implement login with gmail and storing data into datastore(bigtable),but i got an exception,error code is 500. 在我的项目中,我必须实现用gmail登录并将数据存储到datastore(bigtable)中,但出现异常,错误代码为500。

 com.google.gson.stream.MalformedJsonException:
 Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 12 path $

The line number is 88 and the code is:

   JsonObject json = (JsonObject)new JsonParser().parse(outputString.trim());
            String access_token = json.get("access_token").getAsString();
            System.out.println(access_token);

Instead of using JsonObject, try Gson library to convert from Json to String and vice versa. 代替使用JsonObject,尝试使用Gson库将Json转换为String,反之亦然。 For a thorough example, see this answer . 有关完整示例,请参见此答案

If you first create a response class and then serialize it with Gson (like shown in that answer), then you make sure that you are creating a well formatted Json String. 如果您首先创建一个响应类,然后使用Gson对其进行序列化(如该答案所示),那么请确保您正在创建格式良好的Json String。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM