如何使用 Json Jackson 解析带有特殊字符注释的 JSON 图?
这是我的图表 "seriesType": { “代码”:“83001”, “$”:“系列” }
我如何用 json jackson 解析这个 json?我无法这样做,因为美元符号产生了错误。
我试过了
public Dollar serieType;
public class Dollar {
public int code;
public String $;
}
// is is the input stream
jp = jsonFactory.createJsonParser(is);
serieType = objectMapper.readValue(jp, Dollar.class);
strBuffer.append("serieType: " + dollar.$ + "\n");
// 这是我尝试过的一些方法,我确信问题是由美元符号引起的。
我尝试获取像这样的值 String s=tvseries.serieType.$
这是堆栈跟踪 01-02 10:48:03.905: W/ActivityManager(58): Launch timeout has已过期,放弃唤醒锁! 01-02 10:48:04.623:W/ActivityManager(58):HistoryRecord 的活动空闲超时{5b799e28 com.test.jackson/.MainAlloCine} 01-02 10:48:07.886:W / System.err(275):java.lang.NullPointerException 01-02 10:48:07.895:W / System.err(275):在com.test.jackson.MainAlloCine.onCreate(MainAlloCine.java:49) 01-02 10:48:07.895:W / System.err(275):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 01-02 10:48:07.895:W / System.err(275):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 01-02 10:48:07.895:W / System.err(275):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 01-02 10:48:07.895:W / System.err(275):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125) 01-02 10:48:07.895: W/System.err(275): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 01-02 10:48:07.895:W / System.err(275):在android.os.Handler.dispatchMessage(Handler.java:99) 01-02 10:48:07.895:W / System.err(275):在android.os.Looper.loop(Looper.java:123) 01-02 10:48:07.895:W / System.err(275):在android.app.ActivityThread.main(ActivityThread.java:4627) 01-02 10:48:07.895:W / System.err(275):在java.lang.reflect.Method.invokeNative(本机方法) 01-02 10:48:07.895:W / System.err(275):在java.lang.reflect.Method.invoke(Method.java:521) 01-02 10:48:07.905: W/System.err(275): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 01-02 10:48:07.905:W / System.err(275):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 01-02 10:48:07.905:W / System.err(275):在dalvik.system.NativeStart.main(本机方法)
here is my graph "seriesType": {
"code": "83001",
"$": "Série"
}
How do I parse this json with json jackson? I am not able to because the dollar sign is generating an error.
i tried this
public Dollar serieType;
public class Dollar {
public int code;
public String $;
}
// is is the input stream
jp = jsonFactory.createJsonParser(is);
serieType = objectMapper.readValue(jp, Dollar.class);
strBuffer.append("serieType: " + dollar.$ + "\n");
// It's some how what i tried, i am sure that the problem is caused by the dollar sign.
I tried to get a value like this String s=tvseries.serieType.$
and this is the stacktrace 01-02 10:48:03.905: W/ActivityManager(58): Launch timeout has expired, giving up wake lock!
01-02 10:48:04.623: W/ActivityManager(58): Activity idle timeout for HistoryRecord{5b799e28 com.test.jackson/.MainAlloCine}
01-02 10:48:07.886: W/System.err(275): java.lang.NullPointerException
01-02 10:48:07.895: W/System.err(275): at com.test.jackson.MainAlloCine.onCreate(MainAlloCine.java:49)
01-02 10:48:07.895: W/System.err(275): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-02 10:48:07.895: W/System.err(275): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
01-02 10:48:07.895: W/System.err(275): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-02 10:48:07.895: W/System.err(275): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-02 10:48:07.895: W/System.err(275): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-02 10:48:07.895: W/System.err(275): at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 10:48:07.895: W/System.err(275): at android.os.Looper.loop(Looper.java:123)
01-02 10:48:07.895: W/System.err(275): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-02 10:48:07.895: W/System.err(275): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 10:48:07.895: W/System.err(275): at java.lang.reflect.Method.invoke(Method.java:521)
01-02 10:48:07.905: W/System.err(275): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-02 10:48:07.905: W/System.err(275): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-02 10:48:07.905: W/System.err(275): at dalvik.system.NativeStart.main(Native Method)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需添加 @JsonProperty 注释:
假设您的问题出在 Java 编译器上,它不允许您在名称中使用美元字符(因为它在内部使用内部类名称等)。
编辑:
查看确切的 JSON,另一个潜在问题很简单:您的结构不匹配。您需要一个包装对象:
并绑定到该对象。但和往常一样,这种额外的包装似乎……嗯,额外的。为什么服务坚持要添加呢?
Just add
@JsonProperty
annotation:assuming your problem is with Java compiler which does not let you use dollar character in names (because it uses it internally how inner class names etc).
EDIT:
Looking at exact JSON, the other potential issue is simple: your structure does not match. You need one wrapper object:
and bind to that. But as usual, this extra level of wrapping seems... well, extra. Why does service insist on adding it?