简体   繁体   中英

Parse.com says “invalid character '\'' looking for beginning of value”

When I click finish import, Parse.com says "invalid character '\\'' looking for beginning of value". However, there is not a single character "\\" in my entire file. You can check it below.

Apparently, this is because of using single quotes instead of double quotes. Can I use "name": 'Samat', instead of "name": "Samat" ?

https://gist.github.com/samatdav/61db29a676da21dc4bbd

The JSON format specification is very clear about this: String values must be enclosed in double quotes. Single quotes or unquoted values (other than true, false, null, numbers or nested object/array definitions) are not allowed.

JavaScript's internal object notation is much less strict in that regard, as it generally allows single-quoted strings. However, JSON is only a subset of the original JavaScript object notation syntax.

The error itself is telling you the invalid character is ' the single quote. It's just represented as a \\' since they are using single quotes to enclose the invalid character the character must be escaped.

"invalid character '\'' looking for beginning of value"
                   ^  ^ notice the single quotes. 

The issue in your gist is that single quotes are not valid representation of strings in JSON.

Note

{
    "foo": 'bar'
}

Yields the following error on JSONLint

Parse error on line 2:
{    "foo": 'bar'}
------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

For anyone that might need this later. As ipfs daemon --help suggests, the cors domain can be set via

>ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'

which in Windows yields

Error: failed to unmarshal json. invalid character '\\'' looking for beginning of value

The correct version should be

>ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin "[\\"*\\"]"

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