You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
the only difference between userStr1 and userStr2 is there is a blank betweent ':' and '[' after "models".
`
public class FastJsonTest {
public static void main(String[] args) {
String userStr1 = "{"id":"qfHdV0ez0N10", "ext":{"models": ["10000","10002"] } }";
String userStr2 = "{"id":"qfHdV0ez0N10", "ext":{"models":["10000","10002"] } }";
User user = JSON.parseObject(userStr1, User.class);
System.out.println(user);
user = JSON.parseObject(userStr2, User.class);
System.out.println(user);
}
public static class User {
private String id;
private UserExt ext;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public UserExt getExt() {
return ext;
}
public void setExt(UserExt ext) {
this.ext = ext;
}
@Override
public String toString() {
return "User{" +
"id='" + id + '\'' +
", ext=" + ext +
'}';
}
}
public static class UserExt {
private List<String> models;
public List<String> getModels() {
return models;
}
public void setModels(List<String> models) {
this.models = models;
}
@Override
public String toString() {
return "UserExt{" +
"models=" + models +
'}';
}
}
}`
you will get the result:
User{id='qfHdV0ez0N10', ext=UserExt{models=[10000, 10002]}}
Exception in thread "main" com.alibaba.fastjson.JSONException: unclosed.str
at com.alibaba.fastjson.parser.JSONLexerBase.scanSymbol(JSONLexerBase.java:678)
at com.alibaba.fastjson.parser.JSONLexerBase.scanSymbol(JSONLexerBase.java:624)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:241)
at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer.parseRest(ASMJavaBeanDeserializer.java:100)
at Fastjson_ASM_UserExt_3.deserialze(Unknown Source)
at com.alibaba.fastjson.parser.deserializer.DefaultFieldDeserializer.parseField(DefaultFieldDeserializer.java:33)
at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer.parseField(ASMJavaBeanDeserializer.java:74)
at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer$InnerJavaBeanDeserializer.parseField(ASMJavaBeanDeserializer.java:86)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:330)
at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer.parseRest(ASMJavaBeanDeserializer.java:100)
at Fastjson_ASM_User_1.deserialze(Unknown Source)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:551)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:251)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:227)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:186)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:304)
at com.foxdsp.adserver.test.FastJsonTest.main(FastJsonTest.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Process finished with exit code 1
_
the userStr1 is deserialize successfully. but userStr2 not.
Please check this , thx.
The text was updated successfully, but these errors were encountered:
please run the code as follows:
the only difference between userStr1 and userStr2 is there is a blank betweent ':' and '[' after "models".
`
public class FastJsonTest {
public static void main(String[] args) {
String userStr1 = "{"id":"qfHdV0ez0N10", "ext":{"models": ["10000","10002"] } }";
String userStr2 = "{"id":"qfHdV0ez0N10", "ext":{"models":["10000","10002"] } }";
User user = JSON.parseObject(userStr1, User.class);
System.out.println(user);
user = JSON.parseObject(userStr2, User.class);
System.out.println(user);
}
}`
you will get the result:
User{id='qfHdV0ez0N10', ext=UserExt{models=[10000, 10002]}}
Exception in thread "main" com.alibaba.fastjson.JSONException: unclosed.str
at com.alibaba.fastjson.parser.JSONLexerBase.scanSymbol(JSONLexerBase.java:678)
at com.alibaba.fastjson.parser.JSONLexerBase.scanSymbol(JSONLexerBase.java:624)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:241)
at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer.parseRest(ASMJavaBeanDeserializer.java:100)
at Fastjson_ASM_UserExt_3.deserialze(Unknown Source)
at com.alibaba.fastjson.parser.deserializer.DefaultFieldDeserializer.parseField(DefaultFieldDeserializer.java:33)
at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer.parseField(ASMJavaBeanDeserializer.java:74)
at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer$InnerJavaBeanDeserializer.parseField(ASMJavaBeanDeserializer.java:86)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:330)
at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer.parseRest(ASMJavaBeanDeserializer.java:100)
at Fastjson_ASM_User_1.deserialze(Unknown Source)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:551)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:251)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:227)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:186)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:304)
at com.foxdsp.adserver.test.FastJsonTest.main(FastJsonTest.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Process finished with exit code 1
_
the userStr1 is deserialize successfully. but userStr2 not.
Please check this , thx.
The text was updated successfully, but these errors were encountered: