我有这个字符串:
String s = "VClass2 [id=null, provider=null, venueId=VenueID [t10=555, t1=333, id=12033], categories=[FOOD_AND_DRINK], name=מסעדת גוז׳ ודניאל , englishName=null, description=null]";
和这个对象:
public class VClass2 implements Cloneable, Serializable, Externalizable {
public String id;
public String provider;
@Transient
public VenueID venueId;
@Column(name="category")
@Serialize(StringToArray.class)
public String[] categories;
public String name;
public String englishName;
public String description;
@Transient
public UserInfo lastUpdatedByInfo;
我发现它们在结构上并不完全匹配。
如何解析字符串并最容易填写此类的实例?
我可以操作输入字符串,但是为了让Gson解析顺利进行,应该怎么样?
public class MyTest {
Gson gson = new Gson();
String s = "VClass2 [id=null, provider=null, venueId=VenueID [t10=555, t1=333, id=12033], categories=[FOOD_AND_DRINK], name=מסעדת גוז׳ ודניאל , englishName=null, description=null]";
@Before
public void setUp() throws Exception {
}
@Test
public void foo()
{
Venue2 venue = gson.fromJson(s, VClass2.class);
}
}
答案 0 :(得分:1)
Gson希望在JSON format中输入。这意味着:
:
代替=
{}
示例:
{"id":null, "provider":null, "venueId":{"t10":555, "t1":333, ...