gpt4 book ai didi

json - 常规.json.JsonException : expecting '}' or ',' but got current char

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

我正在尝试让一段代码为我工作,但运气不佳。所以我把代码分解成这个让我伤心的小片段。

谁能帮助确定为什么会发生这种错误?

import groovy.json.JsonSlurper;

String index = '[{accessCode=d20in9t, createdAt=2016-09-22T18:27:47.904Z, id=22cbf7c2-5d4e-4afe-a385-ddefb6e6dcf0, licenseType=mobileAppLicensesWithDevice, name=Lead Retrieval - Device Rental & App license, owner={entityType=exhibitor, id=df04e5e4-b69a-4585-8a26-659a8f8ae15f}, readableId=npy5gcqnz8t, termId=630493a4-4a70-4f4f-afaf-31610c14c181, updatedAt=2016-09-22T18:27:47.904Z}, {accessCode=fqcg0w9, createdAt=2016-09-22T18:27:47.904Z, id=74270a86-dfe8-4b58-82e7-080dd57ce57a, licenseType=mobileAppLicensesWithDevice, name=Lead Retrieval - Device Rental & App license, owner={entityType=exhibitor, id=df04e5e4-b69a-4585-8a26-659a8f8ae15f}, readableId=3atchw5lhai, termId=630493a4-4a70-4f4f-afaf-31610c14c181, updatedAt=2016-09-22T18:27:47.904Z}, {accessCode=o6eg9dp, createdAt=2016-09-22T18:27:47.904Z, id=8cc4f312-dae4-4daf-99cb-d060165ec8e8, licenseType=mobileAppLicensesWithDevice, name=Lead Retrieval - Device Rental & App license, owner={entityType=exhibitor, id=df04e5e4-b69a-4585-8a26-659a8f8ae15f}, readableId=q9pqu7nm5oa, termId=630493a4-4a70-4f4f-afaf-31610c14c181, updatedAt=2016-09-22T18:27:47.904Z}]'

def slurper = new groovy.json.JsonSlurper().parseText(index)
slurper.each {
println(it)
}

http://ideone.com/3RrxyX

这是我在脚本中运行时遇到的错误...

groovy.json.JsonException: expecting '}' or ',' but got current char 'a' with an int value of 97
The current character read is 'a' with an int value of 97
expecting '}' or ',' but got current char 'a' with an int value of 97
line number 1
index number 2
[{accessCode=uvrbjeg, createdAt=2016-09-22T19:53:27.971Z, id=0328fce8-832d-499d-a19a-571ce19ce117, licenseType=mobileAppLicensesWithDevice, name=Lead Retrieval - Device Rental & App license, owner={entityType=exhibitor, id=6c3b0b9f-fed0-4b62-a241-f42b896dc0ff}, readableId=5btnmmqe49m, termId=630493a4-4a70-4f4f-afaf-31610c14c181, updatedAt=2016-09-22T19:53:27.971Z}, {accessCode=8fzwy2p, createdAt=2016-09-22T19:53:27.971Z, id=33db29b4-0e0d-449f-9ecf-f126dd745c87, licenseType=mobileAppLicensesWithDevice, name=Lead Retrieval - Device Rental & App license, owner={entityType=exhibitor, id=6c3b0b9f-fed0-4b62-a241-f42b896dc0ff}, readableId=izs6wr742ea, termId=630493a4-4a70-4f4f-afaf-31610c14c181, updatedAt=2016-09-22T19:53:27.971Z}, {accessCode=d4hjfue, createdAt=2016-09-22T19:53:27.971Z, id=8d49d092-3f2f-4801-85ae-aebca5d507d4, licenseType=mobileAppLicensesWithDevice, name=Lead Retrieval - Device Rental & App license, owner={entityType=exhibitor, id=6c3b0b9f-fed0-4b62-a241-f42b896dc0ff}, readableId=ur1onrasbd7, termId=630493a4-4a70-4f4f-afaf-31610c14c181, updatedAt=2016-09-22T19:53:27.971Z}]

任何想法都可以帮助解决这个问题。

最佳答案

您可以更改字符串格式以更正 JSON(带引号的键)或者您可以更改 JsonSlurper 解析类型:

new JsonSlurper().setType(JsonParserType.LAX).parseText(index)

关于json - 常规.json.JsonException : expecting '}' or ',' but got current char,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39647840/

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