简体   繁体   English

JSON结构无法在转换往返中幸存

[英]JSON structure not surviving conversion round trip

This command: 该命令:

ConvertTo-Json (ConvertFrom-Json '{ "abc": [ [1, 2, 3], 4, [5, 6, 7] ] }')

returns: 收益:

{ "abc":  [ [ 1, 2, 3 ], 4, [ 5, 6, 7 ] ] }

However, the following (the same value at a deeper level): 但是,以下内容(在更深层次上为相同的值):

ConvertTo-Json (ConvertFrom-Json '{ "abc": { "abc": [ [ 1, 2, 3 ], 4, [5, 6, 7] ] } }')

returns: 收益:

{ "abc":  { "abc":  [ "1 2 3", 4, "5 6 7" ] } }

Is this a bug? 这是错误吗?

Ideally, I'd like to find out what PowerShell value to pass to ConvertTo-Json in order to produce the JSON in the 2nd example, ie: 理想情况下,我想找出要传递给ConvertTo-Json PowerShell值,以便在第二个示例中生成JSON,即:

'{ "abc": { "abc": [ [ 1, 2, 3 ], 4, [5, 6, 7] ] } }'

I usually use ConvertFrom-Json to find out such values. 我通常使用ConvertFrom-Json找出此类值。

Passing -Depth 3 to ConvertTo-Json solves the problem: -Depth 3传递给ConvertTo-Json可以解决此问题:

ConvertTo-Json -Compress -Depth 3 (ConvertFrom-Json '{ "abc": { "abc": [ [ 1, 2, 3 ], 4, [5, 6, 7] ] } }')

produces: 生产:

{"abc":{"abc":[[1,2,3],4,[5,6,7]]}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 asmx往返json - asmx round trip json Ruby中的往返JSON序列化 - Round-trip JSON serialization in Ruby .NET DateTime往返的JSON序列化不起作用 - JSON serialization of .NET DateTime round trip doesn't work 如何将此JSON往返于PSObject并返回Powershell - How to round-trip this JSON to PSObject and back in Powershell 用于编写配置的数据结构格式(YAML或诸如此类)保留注释的往返解析 - Round-trip parsing of data structure format (YAML or whatnot) preserving comments, for writing configuration Powershell 中的非损坏(具有往返能力)ConvertFrom-Json / ConvertTo-Json - Non-broken (round-trip capable) ConvertFrom-Json / ConvertTo-Json in Powershell 无法在 ASP.NET Core 中往返 JSON - 因为我做了一些愚蠢的事情 - Unable to round-trip JSON in ASP.NET Core - because I did something stupid Rails:JSON 从数据库到 TEXTAREA 的往返在第二次保存时转换为字符串 - Rails: JSON round trip from database to TEXTAREA converts to string on second save 如何使用asp .net web api,实体框架和json(代码优先)来关联对象? - How to round trip an object with relation using asp .net web api, entity framework and json (code first)? 在MVC 3应用程序中,如何进行DateTimes和TimeSpans的简单AJAX / JSON往返? - In an MVC 3 Application, how do I do a simple AJAX/JSON round trip of DateTimes and TimeSpans?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM