我有一个字符串:
[{"product_id":"2","name":'stack"'},{"product_id":"2","name":"overflow"}]"
如何使用 Flexjson 的 JSONDeserializerproduct_id
从上述字符串中获取所有 s?
我有一个名为的类,它具有和之类productinformation
的字段。product_id
name
我有一个字符串:
[{"product_id":"2","name":'stack"'},{"product_id":"2","name":"overflow"}]"
如何使用 Flexjson 的 JSONDeserializerproduct_id
从上述字符串中获取所有 s?
我有一个名为的类,它具有和之类productinformation
的字段。product_id
name
您可以使用这些JSONDeserializer.use()
方法告诉它如何反序列化数组和数组中的每个对象,在这种情况下是 class ProductInformation
。product_id 属性与 flexjson 期望的标准命名不匹配,因此您在对象上的属性需要在其中包含下划线。
String products= "[{\"product_id\": \"123\",\"name\":\"stack\"},{\"product_id\": \"456\",\"name\":\"overflow\"}]";
List<ProductInformation> productInfoList = new JSONDeserializer<List<ProductInformation> >()
.use(null, ArrayList.class)
.use("values",ProductInformation.class)
.deserialize(products);
for(ProductInformation productInformation : productInfoList){
System.out.println(productInformation.getProduct_id();
}
文档的反序列化部分中的“没有训练轮的反序列化”部分详细介绍了其他情况,以考虑类型信息是否不包含在 JSON 字符串中。