LoginSignup
2
2

More than 5 years have passed since last update.

キーに空白が入る時のJsonReaderWriterFactoryの挙動

Posted at

生成されるXElementが変わるっぽい。

テストコードは以下。

JsonReaderWriterFactory.cs

using (var reader = JsonReaderWriterFactory.CreateJsonReader(Encoding.Unicode.GetBytes(json),
                        XmlDictionaryReaderQuotas.Max))
{
  var element = XElement.Load(reader);
}


まずはキーに空白が入ってないパターン。

{"hogehoge":[{"aaa": 123}, {"bbb": 234}]}

<root type="object">
  <hogehoge type="array">
    <item type="object">
      <aaa type="number">123</aaa>
    </item>
    <item type="object">
      <bbb type="number">234</bbb>
    </item>
  </hogehoge>
</root>

次にキーに空白が入ってるパターン。

{"hoge hoge":[{"aaa": 123}, {"bbb": 234}]}

<root type="object">
  <a:item xmlns:a="item" item="hoge hoge" type="array">
    <item type="object">
      <aaa type="number">123</aaa>
   </item>
    <item type="object">
      <bbb type="number">234</bbb>
    </item>
  </a:item>
</root>

原因はよくわかってないので知ってる方居らっしゃれば教えて頂ければ幸いです。
XMLとJSONの仕様の差異とかなのでしょうか。

2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2