JSON
[
{
"id": 1,
"name": "product new"
},
{
"id": 2,
"name": "test12345"
},
{
"id": 3,
"name": "product new"
}
]
爪哇
ArrayList<Product> products
products = new Gson().fromJson(result.toString(), ArrayList<Product>.getClass());
如何将JSON数组转换为基于Product类的ArrayList?
答案 0 :(得分:1)
试试这个:
import com.google.gson.reflect.TypeToken;
ArrayList<Product> products = new Gson().fromJson(results, new TypeToken<ArrayList<Product>>(){}.getType());;