com.alibaba.fastjson.JSONException: illegal identifier : pos 3, json

2022-01-05 14:06:34 浏览数 (1)

项目场景:

在改造基于消息队列请求的接口时, 利用paho模拟发送数据, 项目上解析报错


问题描述:

发送的数据格式如下

项目报错截图如下

错误详情

代码语言:javascript复制
com.alibaba.fastjson.JSONException: illegal identifier :  pos 3, json : {
    "machineKey":"111",
    "data":[
        {
            "businessCode":"002",
            "businessName":"办电",
            "businessType":"缴费",
            "businessHallName":"城南"
        },
        {
            "businessCode":"003",
            "businessName":"开户",
            "businessType":"业务",
            "businessHallName":"城南"
        }
    ]
}
	at com.alibaba.fastjson.parser.JSONLexerBase.scanSymbolUnQuoted(JSONLexerBase.java:829)
	at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:278)
	at com.alibaba.fastjson.parser.DefaultJSONParser.parse(DefaultJSONParser.java:1335)
	at com.alibaba.fastjson.parser.DefaultJSONParser.parse(DefaultJSONParser.java:1301)
	at com.alibaba.fastjson.JSON.parse(JSON.java:152)
	at com.alibaba.fastjson.JSON.parse(JSON.java:162)
	at com.alibaba.fastjson.JSON.parse(JSON.java:131)
	at com.alibaba.fastjson.JSON.parseObject(JSON.java:223)
	at com.sxd.onlinereservation.mqtt.PushCallback.messageArrived(PushCallback.java:83)
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:499)
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:402)
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:206)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
	at java.util.concurrent.FutureTask.run(FutureTask.java)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

原因分析:

解决方案:

改成如下格式:

代码语言:javascript复制
{
"machineKey":"111",
"data":[
{
"businessCode":"002",
"businessName":"办电",
"businessType":"缴费",
"businessHallName":"城南"
},
{
"businessCode":"003",
"businessName":"开户",
"businessType":"业务",
"businessHallName":"城南"
}
]
}

0 人点赞