私は文字列を持っています:
[{"product_id":"2","name":'stack"'},{"product_id":"2","name":"overflow"}]"
Flexjson の JSONDeserializer を使用product_idして、上記の文字列からすべての s を取得するにはどうすればよいですか?
productinformationと のようなフィールドを持つというクラスがproduct_idありnameます。
私は文字列を持っています:
[{"product_id":"2","name":'stack"'},{"product_id":"2","name":"overflow"}]"
Flexjson の JSONDeserializer を使用product_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 文字列に型情報が含まれていないかどうかを検討するために、他のケースの詳細について説明します。