我想将我的字符串输入解析为 json,然后从中获取项目,因此我添加了以下代码:
String data=new String(content.getBytes(),"UTF-8");
String x=data.replaceAll("[\\n\\r\\t]+", "");
System.out.println(x+"=================================================");
FormatedData="id:"+id+"\n"+"name:"+name+"\n"+"comment:"+comment;
String id,name,comment;
JsonParser parser = new JsonParser();
System.out.println(x+"===================================================");
JsonObject obj = (JsonObject) parser.parse(x).getAsJsonObject();
System.out.println(obj+"===============================================");
name = obj.get("organizationNameEN").getAsString();
id = obj.get("id").getAsString();
comment=obj.get("comment").getAsString();
String FormatedData="id:"+id+"\n"+"name:"+name+"\n"+"comment:"+comment;
这是我的 JsonData:
{id:15, organizationNameGE:55, organizationNameEN:5656, cardNumber:6767, startDate:02/04/2018, period:5, endDate:02/10/2018, priority:not so important, $$hashKey:19A, comment:comment, mail:mail}
我正在使用这个库来解析 com.google.gson.JsonParser;但是当我尝试进行此操作时,出现此错误:com.google.gson.stream.MalformedJsonException: Unterminated object at line 1 column 89 path $.startDate I HVAE REMOVED ALL SPACES from STRING 我应该在这里更改什么来摆脱这个错误?