简体   繁体   English

JsonSlurper在单引号和双引号输入之间生成不同的结果

[英]JsonSlurper generating different result between single-quoted and double-quoted input

I want to convert a String to json and using 我想将String转换为json并使用

JsonSlurper.parseText("{'name' : 'robel'}") is Throwing Exception. JsonSlurper.parseText("{'name' : 'robel'}")正在抛出异常。

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 Json需要双引号

You need an instance of JsonSlurper, and double quotes in your json: 您需要一个JsonSlurper实例,并在json中使用双引号:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 python 中获得双引号 json 主体? - how to get double-quoted json body in python? 如何使用jq漂亮打印单引号的JSON文件 - how to prettyprint a single-quoted JSON file using jq Powershell & Curl - 在单引号 JSON 正文中使用变量 - Powershell & Curl - Using variables inside single-quoted JSON body JSON.parse:期望的双引号属性名称 - JSON.parse: expected double-quoted property name 传递给javascript的eval的单引号/双引号字符串之间有区别吗? - Is there a difference between single/double quoted strings passed to javascript's eval? 分隔空格,避免使用双引号JS字符串:从'a“ b \\\\” c” d'到['a','” b \\\\“ c”','d'] - Split spaces avoiding double-quoted JS strings : from 'a “b \\” c“ d ' to ['a','”b \\“ c”','d'] JSON对象属性名称必须用双引号作为官方标准吗? - In What Standard is it Made Official That JSON Object Property Names Must Be Double-Quoted? 在 Command Line Arguments Gradle Java App on Windows 中传递 JSON(双引号元素和值) - Passing JSON (double-quoted elements and values) in Command Line Arguments in Gradle Java App on Windows JSON.parse:预期的双引号属性名称(var json = JSON.parse(xhr.responseText);) - JSON.parse: expected double-quoted property name (var json = JSON.parse( xhr.responseText );) Primefaces。 客户端错误:JSON.parse:JSON数据的第1行第26列中应使用双引号引起的属性名 - Primefaces. Error on client: JSON.parse: expected double-quoted property name at line 1 column 26 of the JSON data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM