gpt4 book ai didi

java - 我如何解析这个类似于 JSON 的字符串?

转载 作者:行者123 更新时间:2023-11-30 07:39:48 26 4
gpt4 key购买 nike

在我的项目中,我向 Stripe 提交了一个请求,它返回了文件中的一组卡片

{
data = [{
address_zip_check = null,
country = US,
last4 = 4242,
funding = credit,
metadata = {},
address_country = null,
address_state = null,
exp_month = 4,
exp_year = 2024,
address_city = null,
tokenization_method = null,
cvc_check = pass,
address_line2 = null,
address_line1 = null,
fingerprint = TAw8rdASXn64,
name = null,
id = card_1FiwAkASrE1bJO6aaQ,
address_line1_check = null,
address_zip = null,
dynamic_last4 = null,
brand = Visa,
object = card,
customer = cus_GDUhOvTHo9
}, {
address_zip_check = null,
country = US,
last4 = 4444,
funding = credit,
metadata = {},
address_country = null,
address_state = null,
exp_month = 4,
exp_year = 2024,
address_city = null,
tokenization_method = null,
cvc_check = pass,
address_line2 = null,
address_line1 = null,
fingerprint = NW3wMUNiaA8g,
name = null,
id = card_1Fj3ZoASrE1bJO6aFu,
address_line1_check = null,
address_zip = null,
dynamic_last4 = null,
brand = MasterCard,
object = card,
customer = cus_GDUhOvTHo9
}], has_more = false, url = /v1/customers / cus_GDUhOvTHo9 / sources, object = list

}

问题是 JSONObjectJSONArray 无法将其识别为有效的 JSON。

JSONObject jsonObject = new JSONObject(jsonStr);
JSONArray jsonArray = jsonObject.getJSONArray("data");

"Expected literal value..."

我怎样才能解析这些信息?

有没有办法修改这个字符串,使其可以被识别为有效的 JSON?

我是否必须编写自己的解析方法?

最佳答案

returns back an array of cards on file

  1. Stripe-API 返回有效的 json [1]。

  2. 我猜失败发生在两者之间,例如当您将响应序列化到一个文件时。确保使用正确的 json 工具!

  3. 您的打印看起来像一个普通的 Map.toString()。只需将 map 直接传递给 new JSONObject(mymap)

[1] curl https://api.stripe.com/v1/customers -u sk_test_4eC39HqLyjWDarjtT1zdp7dc:

关于java - 我如何解析这个类似于 JSON 的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59052629/

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