本文介绍了如何将xml转换为json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在web方法中iam返回xml字符串,如 MemoryStream ms = new MemoryStream(); dsCustomer.WriteXml(ms,XmlWriteMode.IgnoreSchema); StreamReader sr = new StreamReader(ms,System.Text.Encoding.UTF8); ms.Position = 0 ; String strXml = sr.ReadToEnd(); sr.Close(); ms.Close(); return strXml; 成功方法json我打电话给 $。ajax({类型: POST, contentType: application / json; charset = utf-8, url:' url', data: {}, async: false , dataType: xml,成功:功能(数据){ build_menu(数据) )}, 我从webmethod返回的xml数据,如 < NewDataSet > < 表 > < UserID > 17727 < / UserID > < 用户 > 测试用户< /用户 > < 订购 / > < /表 > < 表1 > < id > 21 < / id > < CustomerID > 12872 < / CustomerID > < 客户 > Actavis Group < /客户 > < Primarycsrid > 16231 < / Primarycsrid > < PrimaryCSR > Kavitha Rani Aryamarati < / PrimaryCSR > < ImplicitSameBranchAccess > ; true < / ImplicitSameBranchAccess > < azGroup > ; A - C < / azGroup > < IsLoggedOnUserCustomer > false < / IsLoggedOnUserCustomer > < / Table1 > < / NewDataSet > i希望将我的输出显示为 {NewDataSet:{Table:[ {UserID:17727,用户:测试用户},],表1:[ { id:21,CustomerID:12872,客户:Ac tavis Group,Primarycsrid:16231,PrimaryCSR:Kavitha Rani Aryamarati,ImplicitSameBranchAccess:true,azGroup: A - C,IsLoggedOnUserCustomer:false},] } } 如何toonvert xml to json请帮帮我解决方案 in web method iam returning xml string like MemoryStream ms = new MemoryStream(); dsCustomer.WriteXml(ms, XmlWriteMode.IgnoreSchema); StreamReader sr = new StreamReader(ms, System.Text.Encoding.UTF8); ms.Position = 0; String strXml = sr.ReadToEnd(); sr.Close(); ms.Close(); return strXml;in success method json iam calling like $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: 'url', data: "{}", async: false, dataType: "xml", success: function (data) { build_menu(data) },my returned xml data from webmethod like <NewDataSet> <Table> <UserID>17727</UserID> <User>test user</User> <Ordering /> </Table><Table1> <id>21</id> <CustomerID>12872</CustomerID> <Customer>Actavis Group</Customer> <Primarycsrid>16231</Primarycsrid> <PrimaryCSR>Kavitha Rani Aryamarati</PrimaryCSR> <ImplicitSameBranchAccess>true</ImplicitSameBranchAccess> <azGroup>A - C</azGroup> <IsLoggedOnUserCustomer>false</IsLoggedOnUserCustomer> </Table1></NewDataSet>i want to show my out put as { "NewDataSet": { "Table": [ { "UserID": "17727", "User": "test user" },], "Table1": [ { "id": "21", "CustomerID": "12872", "Customer": "Actavis Group", "Primarycsrid": "16231", "PrimaryCSR": "Kavitha Rani Aryamarati", "ImplicitSameBranchAccess": "true", "azGroup": "A - C", "IsLoggedOnUserCustomer": "false" },] }}how toonvert xml to json please help me 解决方案 这篇关于如何将xml转换为json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-31 10:06