【问题标题】:Details about the json:Array feature of Newtonsoft.JSON XML to JSON converter有关 Newtonsoft.JSON XML 到 JSON 转换器的 json:Array 功能的详细信息
【发布时间】:2016-09-13 21:28:25
【问题描述】:

参考这个使用“json:Array”的例子:Converting between JSON and XML

我有两个问题:

  1. 命名空间必须是“json”吗? IE。如果 ns2 匹配回 "xmlns:ns2='http://james.newtonking.com/projects/json'" 可以吗?

  2. 可以省略命名空间吗?我可以只输入“Array='true'”吗?

我将尝试通过反复试验进行测试,但我想也许有人会知道答案,或者将来有人想知道。

这并不重要,但我的 XML 是由 BizTalk 2010 生成的,我正在使用 WCF CustomBehavior 来调用 NewtonSoft,如下所示:

private static ConvertedJSON ConvertXMLToJSON(string xml)
    {
    // To convert an XML node contained in string xml into a JSON string   
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(xml);
    ConvertedJSON convertedJSON = new ConvertedJSON();
    convertedJSON.JSONtext = JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.None);
    convertedJSON.rootElement = doc.DocumentElement.Name;
    return convertedJSON;
    }

【问题讨论】:

  • 对于更高版本的 BizTalk 2013 R2 及更高版本,您将使用 JSON 解码器/编码器,您不需要这样做。在那个版本中,XML 命名空间可以是你喜欢的任何东西,尽管我相信它也使用了 Newtonsoft。
  • 我知道,但目前无法在此客户端使用。 :(

标签: json xml json.net biztalk biztalk-2010


【解决方案1】:

看起来命名空间必须与他们提供的完全一致:

  string xmlToConvert2 = "<myRoot xmlns:json='http://james.newtonking.com/projects/json'><MyText json:Array='true'>This is the text here</MyText><Prices><SalesPrice>10.00</SalesPrice></Prices></myRoot>";
  string strJSON2 = ConvertXMLToJSON(xmlToConvert2);

与普通 xml 一样,命名空间前缀可以是任何值。下面的工作与上述一样好。

string xmlToConvert3 = "<myRoot xmlns:abc='http://james.newtonking.com/projects/json'><MyText abc:Array='true'>This is the text here</MyText><Prices><SalesPrice>10.00</SalesPrice></Prices></myRoot>";
string strJSON3 = ConvertXMLToJSON(xmlToConvert3);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-23
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多