The url in json contains backslashes

2019-05-30 10:41发布

I was just wondering why my wcf rest returns json which contains backslahses in the url. it is as below:

https:\/\/s3.amazonaws.com\/reiaustralia\/1fc00dfab25044ecb31e4882121b535e\/jpg\/download.jpg?AWSAccessKeyId=AKIAISTDESL6TBRAVM4Q&Expires=1380692091&Signature=MduuaUAjQRisadtM%2FDuVDemexLY%3D

Thanks

标签: json wcf rest
3条回答
再贱就再见
2楼-- · 2019-05-30 11:06

They are just escape characters, and when u consume the string in your application it would just be fine

查看更多
男人必须洒脱
3楼-- · 2019-05-30 11:15

Because // (double slash) in javascript means comment and /{string}/ (string inside slash) is mean regula expression.

So. To keep correct value in json it have to put \ (back slash) in front of / (slash).

查看更多
做自己的国王
4楼-- · 2019-05-30 11:21

Forward slashes can be escaped with a backslash in JSON, but they don't have to be. So either one of the following:

{"url":"http://www.example.com/"}
or
{"url":"http\/\/www.example.com\/"}

Will parse into an object which has a url property whose string value is http://www.example.com/.

Some technologies will escape out the slashes when generating JSON, and some won't. PHP, for example, has an option called JSON_UNESCAPED_SLASHES which lets you control whether or not to escape your slashes.

You can get see the various escape characters from the json.org home page in the "string" section.

查看更多
登录 后发表回答