javascript 是否可以将xml写入json对象?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9264470/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to write xml into json object?
提问by Eric Frick
I'm having issues in javascript with putting a var that contains xml string into a object and then send it via ajax with jQuery.
我在 javascript 中遇到问题,将包含 xml 字符串的 var 放入对象中,然后使用 jQuery 通过 ajax 发送它。
The question would be: is it possible to have a xml string into a json object ?
问题是:是否可以将 xml 字符串放入 json 对象中?
{"a":"a","b":"b", "xml":"<test r='r'></test>"}
Thanks in advance
提前致谢
回答by Soumyadip Das
Your XML will be like this:
您的 XML 将是这样的:
< test r="r"> </test>
Replace as follows:
替换如下:
& = &
" = "
' = '
< = <
> = >
/ = /
回答by Ivan Kolodyazhny
Yes, of course. Your code is working well:
当然是。您的代码运行良好:
var obj = {"a":"a","b":"b", "xml":"<test r='r'></test>"}
alert(obj.xml)