如何格式化List< List< int>>作为JSON文件中的表格? [英] How to format List<List<int>> as a table in JSON file?

查看:101
本文介绍了如何格式化List< List< int>>作为JSON文件中的表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Newtonsoft.Json库对.NET对象进行序列化和反序列化. 我要序列化的东西之一是表(表示为List<List<int>>). 我需要的是像表格一样在序列化文件中格式化它们,而不是像现在那样格式化一堆列.有什么办法可以做到这一点?

I use Newtonsoft.Json library for serializing and deserializing .NET objects. One of the things I am serializing are tables (represented as List<List<int>>). What I need is to format them in the serialized file like a table, not like a bunch of columns as they are formatted now. Is there any way to achieve this?

现在,我在json文件中具有以下格式:

Now, I have the following formatting in the json-file:

"Table": [
          [
            1024,
            1024,
            1024,
            1024    
          ],
          [
            1024,
            1024,
            1024,
            1024
          ],
          [
            1024,
            1024,
            1024,      
            1024           
          ]
         ]

我想实现的是这样:

"Table": [
          [1024, 1024, 1024, 1024],
          [1024, 1024, 1024, 1024],
          [1024, 1024, 1024, 1024]                           
         ]

推荐答案

我想要一种更紧凑的格式,关于这个的问题下面已经有一些评论.
如果要提高可读性,可以使用List<Map<string /*columndName*/, int>>

I you want a more compact format there are already some comments below your question about that.
If you want more readability you could use a list of mapping of columnName to columnValue by List<Map<string /*columndName*/, int>>

这篇关于如何格式化List&lt; List&lt; int&gt;&gt;作为JSON文件中的表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆