我只是想知道我是否将JSON推得太远了?如果有人之前打过这个?
我有一个xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<customermodel:Customer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:customermodel="http://customermodel" xmlns:personal="http://customermodel/personal" id="1" age="1" name="Joe">
<bankAccounts xsi:type="customermodel:BankAccount" accountNo="10" bankName="HSBC" testBoolean="true" testDate="2006-10-23" testDateTime="2006-10-23T22:15:01+08:00" testDecimal="20.2" testTime="22:15:01+08:00">
<count>0</count>
<bankAddressLine>HSBC</bankAddressLine>
<bankAddressLine>London</bankAddressLine>
<bankAddressLine>31 florence</bankAddressLine>
<bankAddressLine>Swindon</bankAddressLine>
</bankAccounts>
</customermodel:Customer>
Run Code Online (Sandbox Code Playgroud)
其中包含元素和属性....
当我转换为JSON时,我给了我:
{"customermodel:Customer":{"id":"1","name":"Joe","age":"1","xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance","bankAccounts":{"testDate":"2006-10-23","testDecimal":"20.2","count":"0","testDateTime":"2006-10-23T22:15:01+08:00","bankAddressLine":["HSBC","London","31 florence","Swindon"],"testBoolean":"true","bankName":"HSBC","accountNo":"10","xsi:type":"customermodel:BankAccount","testTime":"22:15:01+08:00"},"xmlns:personal":"http://customermodel/personal","xmlns:customermodel":"http://customermodel"}}
Run Code Online (Sandbox Code Playgroud)
那么我也发送这个客户端..它转换为js对象(或其他)编辑一些值(元素),然后将其发送回服务器.
所以我得到了JSON字符串,并将其转换回XML:
<customermodel:Customer>
<id>1</id>
<age>1</age>
<name>Joe</name>
<xmlns:xsi>http://www.w3.org/2001/XMLSchema-instance</xmlns:xsi>
<bankAccounts>
<testDate>2006-10-23</testDate>
<testDecimal>20.2</testDecimal>
<testDateTime>2006-10-23T22:15:01+08:00</testDateTime>
<count>0</count>
<bankAddressLine>HSBC</bankAddressLine>
<bankAddressLine>London</bankAddressLine>
<bankAddressLine>31 florence</bankAddressLine>
<bankAddressLine>Swindon</bankAddressLine>
<accountNo>10</accountNo>
<bankName>HSBC</bankName>
<testBoolean>true</testBoolean>
<xsi:type>customermodel:BankAccount</xsi:type>
<testTime>22:15:01+08:00</testTime>
</bankAccounts>
<xmlns:personal>http://customermodel/personal</xmlns:personal>
<xmlns:customermodel>http://customermodel</xmlns:customermodel>
</customermodel:Customer>
Run Code Online (Sandbox Code Playgroud)
并且有问题,似乎不知道元素/属性之间的区别所以我无法检查XSD以检查它现在是否有效?
这个问题有方法解决吗?
我不能成为第一个遇到这个问题的人吗?
作为XML编码,JSON没有意义,没有.如果您想使用和操作XML,那么使用和操作XML.
JSON适用于需要重量更轻,更易于解析,更易于编写和阅读的内容.它有一个相当简单的结构,既不比XML更好也不差,只是不同.它具有列表,关联,字符串和数字,而XML具有嵌套的元素,属性和实体.虽然你可以准确地对每一个进行编码,但你必须问问自己为什么要这样做; 如果您希望JSON使用JSON,并且您希望XML使用XML.
| 归档时间: |
|
| 查看次数: |
551 次 |
| 最近记录: |