简体   繁体   中英

JsonSlurper generating different result between single-quoted and double-quoted input

I want to convert a String to json and using

JsonSlurper.parseText("{'name' : 'robel'}") is Throwing Exception.

I tried changing it to

JsonSlurper.parseText('{"name" : "robel"}')

and it works fine. All i did to the first code is substitute the the single cote with double cote and vice versa .can some one tell me why this is happening and how to solve it?

Both things in your question are the same?

Json requires double quotes

You need an instance of JsonSlurper, and double quotes in your json:

new JsonSlurper().parseText('{"name" : "robel"}')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM