The url in json contains backslashes

跟風遠走 提交于 2020-01-23 17:27:12

问题


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


回答1:


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.




回答2:


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).




回答3:


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



来源:https://stackoverflow.com/questions/19130605/the-url-in-json-contains-backslashes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!