- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何用 gson 解析这个结果数组?。我坚持了两天我无法解析。从 SO 和其他几个地方,我发现我需要定义一个顶级容器,但我不知道如何完成它的定义。
results:[
{
"SupplierCatalog": {
"supplier_catalog_id": "139",
"distributor_id": "57",
"distributor_asking_price": "999.99",
"supplier_id": null,
"product_name": "jjjjjjjj j j j j j j jj j jjjjjjjjjjjj",
"product_description": "kkkkkkkkkkkkkk k k k k"
},
"image_details": {
"isCustomImageProvided": 0,
"isImageUploadedTo": 1,
}
},
{
"SupplierCatalog": {
"supplier_catalog_id": "138",
"distributor_id": "57",
"distributor_asking_price": "69.25",
"supplier_id": null,
"product_name": "i+am+editing+this",
"product_description": "using+wait+for+it..........+the+API"
},
"image_details": {
"isCustomImageProvided": 1,
"isImageUploadedTo": 1,
}
},
{
"SupplierCatalog": {
"supplier_catalog_id": "137",
"distributor_id": "57",
"distributor_asking_price": "69.69",
"supplier_id": null,
"product_name": "Supplier Created Product Sample",
"product_description": "This is a sample description"
},
"image_details": {
"isCustomImageProvided": 1,
"isImageUploadedTo": 1,
}
},
{
"SupplierCatalog": {
"supplier_catalog_id": "136",
"distributor_id": "57",
"distributor_asking_price": "45.58",
"supplier_id": null,
"product_name": "Distributor Created Product Sample",
"product_description": "Blah Blah Blah"
},
"image_details": {
"isCustomImageProvided": 1,
"isImageUploadedTo": 1,
}
},
{
"SupplierCatalog": {
"supplier_catalog_id": "135",
"distributor_id": "57",
"distributor_asking_price": "99.99",
"supplier_id": null,
"product_name": "Distributor Created Product Sample",
"product_description": "In publishing and graphic design, lorem ipsum is a filler text commonly used to demonstrate the graphic elements of a document or visual presentation. Replacing meaningful content that could be distracting with placeholder text may allow viewers to focus on graphic aspects such as font, typography, and page layout.\r\n\r\nThe lorem ipsum text is typically a scrambled section of De finibus bonorum et malorum, a 1st-century BC Latin text by Cicero, with words altered, added, and removed such that it is nonsensical, improper Latin.\r\n\r\nA variation of the ordinary lorem ipsum text has been used in typesetting since the 1960s or earlier, when it was popularized by advertisements for Letraset transfer sheets. It was introduced to the Information Age in the mid-1980s by Aldus Corporation, which employed it in graphics and word processing templates for its desktop publishing program, PageMaker, for the Apple Macintosh.[1]"
},
"image_details": {
"isCustomImageProvided": 1,
"isImageUploadedTo": 1,
}
}
]
我无法解析两个类。所以请帮助。 之后我如何获得个人获取方法。谢谢。
最佳答案
这里是结构的示例,根据您的 json 结果,它可能会略有变化。
package com.example.test;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
public class MainActivity extends Activity {
public static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String json = "{results:[{\"SupplierCatalog\":{\"supplier_catalog_id\": \"139\",\"distributor_id\": \"57\",\"distributor_asking_price\": \"999.99\",\"supplier_id\": null,\"product_name\": \"jjjjjjjj j j j j j j jj j jjjjjjjjjjjj\",\"product_description\": \"kkkkkkkkkkkkkk k k k k\"},\"image_details\": {\"isCustomImageProvided\": 0,\"isImageUploadedTo\": 1}}]}";
JsonParseResult jsonParseResult = new Gson().fromJson(json, JsonParseResult.class);
if (jsonParseResult != null && jsonParseResult.getResult() != null) {
for (Result result : jsonParseResult.getResult()) {
Log.d(TAG, "Result: " + result.toString());
}
}
}
public class JsonParseResult {
@SerializedName("results")
private List<Result> results;
public JsonParseResult(List<Result> results) {
super();
this.results = results;
}
public List<Result> getResult() {
return results;
}
public void setResult(List<Result> results) {
this.results = results;
}
}
public class Result {
@SerializedName("SupplierCatalog")
private SupplierCatalog supplierCatalog;
@SerializedName("image_details")
private ImageDetails imageDetails;
public Result(SupplierCatalog supplierCatalog, ImageDetails imageDetails) {
super();
this.supplierCatalog = supplierCatalog;
this.imageDetails = imageDetails;
}
public SupplierCatalog getSupplierCatalog() {
return supplierCatalog;
}
public void setSupplierCatalog(SupplierCatalog supplierCatalog) {
this.supplierCatalog = supplierCatalog;
}
public ImageDetails getImageDetails() {
return imageDetails;
}
public void setImageDetails(ImageDetails imageDetails) {
this.imageDetails = imageDetails;
}
@Override
public String toString() {
return "Result [supplierCatalog=" + supplierCatalog + ", imageDetails=" + imageDetails + "]";
}
}
public class SupplierCatalog {
@SerializedName("supplier_catalog_id")
private Integer supplierCatalogId;
@SerializedName("distributor_id")
private Integer distributorId;
@SerializedName("distributor_asking_price")
private Double distributorAskingPrice;
@SerializedName("supplier_id")
private Integer supplierId;
@SerializedName("product_name")
private String productName;
@SerializedName("product_description")
private String productDescription;
public SupplierCatalog(Integer supplierCatalogId, Integer distributorId, Double distributorAskingPrice, Integer supplierId, String productName, String productDescription) {
super();
this.supplierCatalogId = supplierCatalogId;
this.distributorId = distributorId;
this.distributorAskingPrice = distributorAskingPrice;
this.supplierId = supplierId;
this.productName = productName;
this.productDescription = productDescription;
}
public Integer getSupplierCatalogId() {
return supplierCatalogId;
}
public void setSupplierCatalogId(Integer supplierCatalogId) {
this.supplierCatalogId = supplierCatalogId;
}
public Integer getDistributorId() {
return distributorId;
}
public void setDistributorId(Integer distributorId) {
this.distributorId = distributorId;
}
public Double getDistributorAskingPrice() {
return distributorAskingPrice;
}
public void setDistributorAskingPrice(Double distributorAskingPrice) {
this.distributorAskingPrice = distributorAskingPrice;
}
public Integer getSupplierId() {
return supplierId;
}
public void setSupplierId(Integer supplierId) {
this.supplierId = supplierId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductDescription() {
return productDescription;
}
public void setProductDescription(String productDescription) {
this.productDescription = productDescription;
}
@Override
public String toString() {
return "SupplierCatalog [supplierCatalogId=" + supplierCatalogId + ", distributorId=" + distributorId + ", distributorAskingPrice=" + distributorAskingPrice + ", supplierId=" + supplierId + ", productName=" + productName + ", productDescription=" + productDescription + "]";
}
}
public class ImageDetails {
@SerializedName("isCustomImageProvided")
private Integer isCustomImageProvided;
@SerializedName("isImageUploadedTo")
private Integer isImageUploadedTo;
public ImageDetails(Integer isCustomImageProvided, Integer isImageUploadedTo) {
super();
this.isCustomImageProvided = isCustomImageProvided;
this.isImageUploadedTo = isImageUploadedTo;
}
public Integer getIsCustomImageProvided() {
return isCustomImageProvided;
}
public void setIsCustomImageProvided(Integer isCustomImageProvided) {
this.isCustomImageProvided = isCustomImageProvided;
}
public Integer getIsImageUploadedTo() {
return isImageUploadedTo;
}
public void setIsImageUploadedTo(Integer isImageUploadedTo) {
this.isImageUploadedTo = isImageUploadedTo;
}
@Override
public String toString() {
return "ImageDetails [isCustomImageProvided=" + isCustomImageProvided + ", isImageUploadedTo=" + isImageUploadedTo + "]";
}
}
}
关于android - 使用gson解析jsonarray中的多个json对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25017847/
我正在使用网络服务请求直方图数据。数据是数组中的一组数组: [[1375056000000,23.284713745117],[1375142400000,3.809531211853], [1375
这是我的 json 文件的相关部分: "categories": [ [ "Belgian Restaurant", "belgian" ],
我目前很困惑,为什么我不能在我的 Android 应用程序中从 JSONArray 中提取 JSONArray。下面给出了一个示例和我的源代码片段。 //The JSON { "cur
我正在尝试解析 JSONObject。 这个 JSONObject 中有一个 JSONArray,它在 JSONArray 中还有另一个 JSONArray。 我试图解析的 json 形式如下。 {
我正在尝试解析对象数据列表中的 JSON 数组 payment_details。 在这里,我已经成功解析了回收站 View 中调用的数据数组,但我无法调用 payment_details 数组。 适配
我正在寻找一个选项,可以将多个值添加到 JSONArray 并将其添加到另一个 JSONArray 中,而无需创建多个变量。例如: JSONArray array1 = new JSONArr
我遇到过一种情况,org.json.JSONArray 对象非常大,这最终会导致延迟和其他问题。因此,我们决定将 JSONArray 分割成更小的 block 。例如,如果 JSONArray 是这样
您好,我正在尝试在另一个 json 数组中解析一个 json 数组。帮我解决这个问题。 我的 Json 数组是 "results":[ { "percentcompleted"
我正在使用 Gson用于解析 json 响应。我需要在 JsonArray 中解析 JSONArry.. 我的回答是.. { "message": "Retreive sucessfully", "f
@GET @Produces("application/json") public Response GetAll() throws JSONException{ tblCategoryDao
我从服务器获取以下 json: { "Data": [ { "Record": [ " d11", "d12"
我正在使用 ajax 将 json 对象从 javascript 传递到 java servlet。 var jsonObj = JSON.stringify(objArray); //Then I
我需要获取作为“结果”内部数组的“示例”数据 JSON FILE 并将其附加到字符串。最简单的方法是什么? 这就是我得到“定义”的方式 private JSONObject queryResults;
我需要从 JSONArray 获取 JSONArray: JSONParser parser = new JSONParser(); JSONObject jObject=(J
我有一个 jsonArray 响应。我需要阅读此响应,其中包含 3 个 jsonArray。 这是 json 响应。这是一个 GET 请求并通过 Volley 请求发送。 [ "0x9000",
在此 Json 响应中,如何使用 Java 访问“smallImageUrls”并获取图像 url? 似乎“smallImageUrls”是“匹配”jsonarray 中的一个数组。如果我错了,请有人
这个问题在这里已经有了答案: Convert string to JSON array (10 个答案) 关闭 5 年前。 如何正确地将此字符串转换为 jsonArray? { "myArr
是否可以从较新的 EJB JSON 库转换为较旧的 org.json 库,而无需依赖 org.json.simple 或 GSON? 在下面的例子中,“buttons”是一个填充的 JsonArr
如何从jsonarray获取jsonarray? 我试过的代码。 for(loop) List stringList = new ArrayLis
我目前是 Json 新手,遇到了一个问题。我搜索了很多但找不到答案! 我从 json url 获取名称列表。名称可以在此 json 文件中重复,但我只想将它们的一条记录保留到我称为“arr”的新数组中
我是一名优秀的程序员,十分优秀!