gpt4 book ai didi

java - 无法将字符串转换为 json 数组并解析

转载 作者:行者123 更新时间:2023-12-01 17:33:28 25 4
gpt4 key购买 nike

我一直坚持字符串、json 转换和解析。它可能看起来很傻,但我无能为力。

这是我来自服务器的响应,它是字符串

[{
"ClientName":"SELVI",
"AccountID":"2040IG20000185",
"ToatalLonaAmount":"35000.0000",
"RepaymentFequencyID":"M",
"RepaymentFequency":"Monthly",
"InterestRate":"25.88",
"EMIAmount":"1883.0000",
"PrincipleOutstanding":"3626.0000",
"InterestOutstanding":"108.0000",
"TotalTerm":"24",
"RemainingTerm":"2",
"ErrorCode":"",
"Response":true,
"ResponseMsg":"",
"Status":"1",
"LoanStatusID":"A",
"LoanStatus":"Active Loan"
}]

我如何解析它并读取值?

请帮我解决这个问题。它看起来像 json 数组,我对此很陌生。

我已经尝试过,但无法读取值

JSONParser parser = new JSONParser();
Object obj1 = parser.parse(response.toString());
JSONArray array = new JSONArray();
array.add(obj1);

//JSONArray jsonarray = new JSONArray();
for (int i = 0; i < array.size(); i++) {
System.out.println("data :"+array.get(i));
}

最佳答案

你可以简单地使用 JSON.parse(jsonValue);

示例如下:

var json = '[{"ClientName":"SELVI","AccountID":"2040IG20000185","ToatalLonaAmount":"35000.0000","RepaymentFequencyID":"M","RepaymentFequency":"Monthly","InterestRate":"25.88","EMIAmount":"1883.0000","PrincipleOutstanding":"3626.0000","InterestOutstanding":"108.0000","TotalTerm":"24","RemainingTerm":"2","ErrorCode":"","Response":true,"ResponseMsg":"","Status":"1","LoanStatusID":"A","LoanStatus":"Active Loan"}]'

var objArr = JSON.parse(json);

for(var i=0; i < objArr.length; i++) {
console.log("Object from array: ", objArr[i])
}

关于java - 无法将字符串转换为 json 数组并解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61080218/

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