Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails JSON解析意外的令牌转义字符_Ruby On Rails_Json_Parsing - Fatal编程技术网

Ruby on rails Rails JSON解析意外的令牌转义字符

Ruby on rails Rails JSON解析意外的令牌转义字符,ruby-on-rails,json,parsing,Ruby On Rails,Json,Parsing,我有一个已转义的字符串,我想将其解析为JSON,但使用rails时不断出现错误 {\"content\":{\"Soass__text_plain__abc_of_study\":\"Some of Study\",\"Dodeeedd\": ........... ........lots more of the string then comes some \u002d1 etc 第160行的分析错误: ... “id”:\u002d1 JSON::ParserE

我有一个已转义的字符串,我想将其解析为JSON,但使用rails时不断出现错误

{\"content\":{\"Soass__text_plain__abc_of_study\":\"Some of Study\",\"Dodeeedd\":
...........
........lots more of the string then comes some \u002d1 etc
第160行的分析错误: ... “id”:\u002d1

JSON::ParserError: 399: unexpected token at '{"spacer":"http://s.c.xxx.yyyy.com/scds/common/u/img/spacer.gif","i18n_get_discovered_upload":"\u003cstrong\u003eGet discovered\u003c/strong\u003e for your work! Add your videos, images, documents...","bg_promo_1":

如何解析JSON?

您可以使用哈希或数组构建JSON,这样更简单、更清晰

hash_of_values = {'foo' => 1, 'bar' => 2}
array_of_values = [hash_of_values]
然后:

JSON.parse(hash_of_values) => "{\"foo\":1,\"bar\":2}"
JSON.parse(array_of_values) => "[{\"foo\":1,\"bar\":2}]"

尝试使用此服务查找JSON中的错误字符:它来自如上所述的源代码,我需要将此“未解析”和您解释的内容颠倒过来