gpt4 book ai didi

java - 如何使用 GSON 解析 JSON 对象之前的数字

转载 作者:行者123 更新时间:2023-12-01 14:52:25 24 4
gpt4 key购买 nike

我如何用 GSON 解析这个?因为这个是以数字“1”和“2”开头的。我已经为以entity_id开头的对象创建了一个对象,当我删除外部json(其中包含“1”)时,该对象正在工作。

但我想一次性解析这整堆代码。那么我应该怎么做才能解析“1”和“2”呢?像 String id 和 List insideobjects 这样的东西?

{
"1": {
"entity_id": "1",
"status": "complete",
"coupon_code": null,
"shipping_description": "Flat Rate - Fixed",
"customer_id": null,
"base_discount_amount": "0.0000",
"base_grand_total": "3422.3800",
"base_shipping_amount": "90.0000",
"base_shipping_tax_amount": "0.0000",
"base_subtotal": "3332.3800",
"base_tax_amount": "0.0000",
"base_total_paid": "3422.3800",
"base_total_refunded": null,
"discount_amount": "0.0000",
"grand_total": "3422.3700",
"shipping_amount": "90.0000",
"shipping_tax_amount": "0.0000",
"store_to_order_rate": "1.0000",
"subtotal": "3332.3700",
"tax_amount": "0.0000",
"total_paid": "3422.3700",
"total_refunded": null,
"base_shipping_discount_amount": "0.0000",
"base_subtotal_incl_tax": "3332.3800",
"base_total_due": "0.0000",
"shipping_discount_amount": "0.0000",
"subtotal_incl_tax": "3332.3700",
"total_due": "0.0000",
"increment_id": "100000001",
"base_currency_code": "EUR",
"discount_description": null,
"remote_ip": "472.15.1.83",
"store_currency_code": "EUR",
"store_name": "Main Website\nMain Website Store\nDefault Store View",
"created_at": "2012-08-10 09:37:17",
"shipping_incl_tax": "90.0000",
"payment_method": "checkmo",
"gift_message_from": null,
"gift_message_to": null,
"gift_message_body": null,
"tax_name": null,
"tax_rate": null,
},
"2": {
"entity_id": "2",
"status": "pending",
"coupon_code": null,
"shipping_description": "Flat Rate - Fixed",
"customer_id": null,
"base_discount_amount": "0.0000",
"base_grand_total": "1140.7900",
"base_shipping_amount": "30.0000",
"base_shipping_tax_amount": "0.0000",
"base_subtotal": "1110.7900",
"base_tax_amount": "0.0000",
"base_total_paid": null,
"base_total_refunded": null,
"discount_amount": "0.0000",
"grand_total": "1140.7900",
"shipping_amount": "30.0000",
"shipping_tax_amount": "0.0000",
"store_to_order_rate": "1.0000",
"subtotal": "1110.7900",
"tax_amount": "0.0000",
"total_paid": null,
"total_refunded": null,
"base_shipping_discount_amount": "0.0000",
"base_subtotal_incl_tax": "1110.7900",
"base_total_due": null,
"shipping_discount_amount": "0.0000",
"subtotal_incl_tax": "1110.7900",
"total_due": null,
"increment_id": "100000002",
"base_currency_code": "EUR",
"discount_description": null,
"remote_ip": "182.11.7.52",
"store_currency_code": "EUR",
"store_name": "Main Website\nMain Website Store\nDefault Store View",
"created_at": "2012-08-15 15:19:35",
"shipping_incl_tax": "30.0000",
"payment_method": "checkmo",
"gift_message_from": null,
"gift_message_to": null,
"gift_message_body": null,
"tax_name": null,
"tax_rate": null,
}
}

最佳答案

对奇数“1”、“2”、...对象使用Map:

Map<String, Order> map = gson.fromJson(json, Map.class);

关于java - 如何使用 GSON 解析 JSON 对象之前的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14704456/

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