gpt4 book ai didi

java - 从java valueobjects创建json对象时出错

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

我试图从我的java bean类创建一个json对象,首先我创建一个StringBuffer并将数据附加到其中,然后将此StringBuffer转换为String,同时将此 String 转换为 json 对象我收到此错误。

org.apache.sling.commons.json.JSONException: Expected a ':' after a key at character 129 of {data:{"id":"5345345","name":"dsfsdf","dep":"","ssc":"dgffdgfdg"},{"id":"123456","name":"SBI","dep":"654321","ssc":"State Bank"}}

第 129 个是倒数第二个字母。有语法问题吗?

最佳答案

将您的数据视为对象数组,

你的 JSON 应该是

{
"data": [
{
"id": "5345345",
"name": "dsfsdf",
"dep": "",
"ssc": "dgffdgfdg"
},
{
"id": "123456",
"name": "SBI",
"dep": "654321",
"ssc": "State Bank"
}
]
}

关于java - 从java valueobjects创建json对象时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25601422/

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