【问题标题】:Android : gson.toJson() doesn't give standard jsonAndroid:gson.toJson() 不提供标准 json
【发布时间】:2016-09-29 04:59:14
【问题描述】:

当我尝试使用 gson.toJson(myObject)Object 转换为 json 格式时,它给了我不标准的 json 格式

当前输出: {\"objects\":[],\"type\":\"price\"}

我需要的是这样的:{"objects":[],"type":"price"}

下面我如何将我的对象转换为 json:

Gson gson = new Gson();
                String dataJson = gson.toJson(MyObject);
                System.out.println("LOG : " + dataJson);

我的问题是:如何使用Gson制作正常的json格式?谢谢。

【问题讨论】:

标签: android json gson android-parser


【解决方案1】:

嗨,R Besar,

        String json="{\\\"objects\\\":[],\\\"type\\\":\\\"price\\\"}";
        Log.d("TAG","Old Json: "+json);

        String newJson=json.replace("\\","");
        Log.d("TAG","New Json: "+newJson);

输出

{\"objects\":[],\"type\":\"price\"}
{"objects":[],"type":"price"}

我想这会对你有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-05
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多