如何解析不带引号的JSON字符串 [英] how to parse unquoted JSON string

查看:1701
本文介绍了如何解析不带引号的JSON字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSON字符串,其中没有引用键和值,我想将其转换为格式正确的JSON。

I have a JSON string where neither the keys nor the values are quoted and I would like to transform it to a correctly formatted JSON.

{basic:{0:{index:0, license:t, nameSID:n, image:"img_left", descriptionSID:t, category:r}}

是否有可以处理它的Java库?我试过杰克逊但它不起作用。

Is there a Java library that could handle it? I tried Jackson but it does not work.

问候,
Jan

regards, Jan

推荐答案

您可以使用 JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES 与杰克逊允许不带引号的字段名称:

You can use JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES with Jackson to allow unquoted field names:

JsonFactory factory = new JsonFactory();
factory.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
JsonParser jp = factory.createJsonParser(new FileInputStream("content.json"));

这篇关于如何解析不带引号的JSON字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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