groovy.json.JsonException:预期为'}'或',',但当前为char [英] groovy.json.JsonException: expecting '}' or ',' but got current char

查看:441
本文介绍了groovy.json.JsonException:预期为'}'或',',但当前为char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让一段代码对我有用,并且运气不佳.因此,我将代码分解为导致我感到悲伤的这个小片段.

I am trying to get a piece of code working for me and not having much luck. So I have broken the code down to this little snippet that is causing me grief.

任何人都可以帮助确定世界上为什么发生此错误吗?

Can anyone help identify why in the world this error is happening?

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

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

This is the error I get when I run it in my script ...

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}]

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

Any ideas would be great to help out with this.

推荐答案

Json键必须用双引号

Json keys have to be in double quotes

您所有的值都是字符串,因此它们也需要用双引号引起来.

All your values are strings, so they also need to be in double quotes.

此外,您需要"key":"value"而不是使用=

Also you need "key":"value" instead of using =

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"}]'

这篇关于groovy.json.JsonException:预期为'}'或',',但当前为char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆