"body": { "buyerName": "wwz", "buyerType": "01", "totalAmountTax": "100", "manualOrderDetails": [ { "amount": "100", "itemName": "cd", "invoiceNature": 1, "itemTaxCode": "123", "taxIncluded": "wwz", "taxRate": "10", "yhzcbs": "01" } ] }怎么用java实现获取"manualOrderDetails"中的值
时间: 2023-07-03 07:33:51 浏览: 53
可以通过以下步骤实现获取"manualOrderDetails"中的值:
1. 定义一个 JSON 对象来存储你的 JSON 数据。
```java
JSONObject jsonObject = new JSONObject(jsonString);
```
其中 `jsonString` 为你的 JSON 字符串。
2. 通过 `getJSONArray` 方法获取 "manualOrderDetails" 对应的 JSON 数组。
```java
JSONArray manualOrderDetailsArray = jsonObject.getJSONArray("manualOrderDetails");
```
3. 遍历 JSON 数组,获取每个对象的值。
```java
for (int i = 0; i < manualOrderDetailsArray.length(); i++) {
JSONObject object = manualOrderDetailsArray.getJSONObject(i);
String amount = object.getString("amount");
String itemName = object.getString("itemName");
int invoiceNature = object.getInt("invoiceNature");
String itemTaxCode = object.getString("itemTaxCode");
String taxIncluded = object.getString("taxIncluded");
String taxRate = object.getString("taxRate");
String yhzcbs = object.getString("yhzcbs");
// Do something with the values...
}
```
注意:上述代码中,`getString` 方法用于获取字符串类型的值,`getInt` 方法用于获取整数类型的值。如果值的类型不匹配,会抛出 JSONException 异常。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)