JSON.NET DeserializeXmlNode to XML Attributes -
how can convert json xml using json.net this:
{data : [{s1 :3, s2 :4}, {s1 :1, s2:9}]}
to
<data s1="3" s2="4" /><data s1="1" s2="9" />
once you've parsed object, pass function this.
ienumerable<xelement> getattributeddataelements(jobject obj, string membername) { return jobject o in obj[membername].asjenumerable() select createnode(membername, o); } xelement createnode(string membername, jobject obj) { return new xelement(membername, jproperty m in obj.asjenumerable() select createnode(m) ); } xobject createnode(jproperty member) { var value = member.value; switch (value.type) { case jtokentype.string: case jtokentype.integer: return new xattribute(member.name, value); default: // assuming others objects return createnode(member.name, (jobject)value); } }
Comments
Post a Comment