简体   繁体   English

C#-杰森作为流到Excel

[英]c#- Json as stream to excel

I have .json files stored in AWS S3 bucket. 我将.json文件存储在AWS S3存储桶中。 I use the function OpenStreamAsync to get a specified file and I want to read it and arrange the items according to the way I expect them to be in the .json file but into excel (I use EEPlus ). 我使用函数OpenStreamAsync来获取指定的文件,并且我想读取该文件并根据我希望它们位于EEPlus文件中但进入excel的方式进行排列(我使用EEPlus )。

What is the best practice to do so? 最佳做法是什么?

{ "name":"John", "age":30, "car":null }

1) create a class that matches your JSON you could use http://json2csharp.com/ 1)创建一个与您的JSON匹配的类,您可以使用http://json2csharp.com/

public class RootObject
{
    public string name { get; set; }
    public int age { get; set; }
    public object car { get; set; }
}

2) use Json.NET to deserialize 2)使用Json.NET反序列化

Install Package

PM> Install-Package Newtonsoft.Json


Code to serialize JSON
var group2 = JObject.Parse(yourjson).ToObject<RootObject>();
  1. Create your EEPlus document with your objects 使用对象创建EEPlus文档

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM