如何使用Microsoft web.api制作json文件 [英] How to make a json file with Microsoft web.api

查看:64
本文介绍了如何使用Microsoft web.api制作json文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用Microsoft Web.API创建Json文件,因为我需要使用以下变量创建一个Json文件:

I would like to know how I can create a Json file with Microsoft Web.API because I need to create a Json file with this variables :

var cardnumber = textboxuser.Text;
var username = Dealerusername;
var token = dealertoken;
var segment = segmentnumber;
var tempo = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");
var total = TotalAmount;
var currency = "EUR";





我的尝试:





What I have tried:

[
  {
    "nomeutilizador": 101315,
    "quantidade": 5,
    "Currency": "EUR",

  }
]



注意:所有对象都是我创建的变量


Note: All objects are variable I created

推荐答案

如何:序列化和反序列化JSON数据| Microsoft Docs [ ^ ]。


阅读本文:在C#中使用JSON& VB [ ^ ]



在文章中,我列出了许多有用的工具。其中一个是 JSON Utils:从JSON生成C#,VB.Net,SQL表,Java和PHP [ ^ ] - 这将从JSON数据生成代码。以下是基于您的示例JSON生成的上述链接的类:

Have a read of this article: Working with JSON in C# & VB[^]

In the article, I list a number of useful utils. one of those is JSON Utils: Generate C#, VB.Net, SQL Table, Java and PHP from JSON[^] - this will generate code from JSON data. Here is the class that the above link generated based on your sample JSON:
 public class DataClass
{
    [JsonProperty("nomeutilizador")]
    public int Nomeutilizador { get; set; }

    [JsonProperty("quantidade")]
    public int Quantidade { get; set; }

    [JsonProperty("Currency")]
    public string Currency { get; set; }
}



要将此类转换为JSON,文章有一个 JsonHelper 类来帮助你做这个。使用:


To convert this class into JSON, the article has a JsonHelper class to help you do this. To use:

var data = new DataClass
{
    // populate properties with data
}

string jsonData = JsonHelper.FromClass(DataClass);


这篇关于如何使用Microsoft web.api制作json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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