-1

我有一个从 Json Api-Call 反序列化的 Json 文件,现在我必须将此文件用作主程序中的对象。

这是其中的一小部分:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Api1
{
    public class EcmSimpleField
    {
        public string value { get; set; }
        public string displayName { get; set; }
        public string internalName { get; set; }
        public string dbName { get; set; }
        public bool visible { get; set; }
        public string type { get; set; }
    }

    public class BaseParameter
    {
        public string value { get; set; }
        public string type { get; set; }
    }

    public class SystemField
    {
        public string value { get; set; }
        public string type { get; set; }
    }

如何将此文件用作主程序中的对象并使用它?

4

2 回答 2

4

为您在上面共享的 json 创建一个类,并使用 Newtonsoft.json dll 或任何其他库对其进行反序列化。

var obj = JsonConvert.DeserializeObject<YourClass>(jsonString);
于 2021-02-18T12:09:47.620 回答
0

该线程可能会对您有所帮助: 如何使用 C# 解析 JSON?

如果您的 JSON 文件具有更改的参数,则需要在数组中检索参数,因为即使“参数”发生更改,数组索引也将始终相同。

于 2021-02-18T12:13:26.970 回答