gpt4 book ai didi

java - 从 JSON 数组中解析字符串数组

转载 作者:行者123 更新时间:2023-11-29 20:06:47 25 4
gpt4 key购买 nike

我在 JSONArray ary2 中有这个;

JSON 字符串是:

[
{
"item_id": "1",
"Head_item_id": "1",
"major_item_id": "1",
"Quantity": "10",
"selling_prize": "20",
"MRP": "90",
"title": "JK Lakshmi PPC Cement",
"SKU": "B2WBUICEM2"
},
{
"item_id": "2",
"Head_item_id": "1",
"major_item_id": "1",
"Quantity": "10",
"selling_prize": "30",
"MRP": "80",
"title": "JK Lakshmi PPC Cement",
"SKU": "B2WBUICEM2"
},
{
"item_id": "3",
"Head_item_id": "1",
"major_item_id": "1",
"Quantity": "10",
"selling_prize": "10",
"MRP": "70",
"title": "Shree Ultra OPC 43 Grade Cement",
"SKU": "B2WBUICEM5"
}
]

我想为每个属性获取字符串数组,例如:

String[] item_id;
String[] Head_item_id;

等无法得到它。请帮忙。

最佳答案

试试这个:

JSONArray arr = new JSONArray(yourJSONresponse);
String[] item_id=new String[array.length()];
String[] Head_item_id=new String[arr .length()];
for(int i = 0; i < arr.length(); i++){
item_id[i]=arr.getJSONObject(i).getString("item_id");
Head_item_id[i]=arr.getJSONObject(i).getString("Head_item_id");
}

关于java - 从 JSON 数组中解析字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35548605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com