繁体   English   中英

Json字符串解析C#行和列

[英]Json String parsing C# Row and Column

我正在从Web服务获取JSON字符串
想要通过C#在for循环中通过C#读取ROW和Column中的JSON字符串我是C#对象编码中的新增功能如果以下Json String的示例更多,帮助更多


[{"_id":"1-1","awid":"1","officeid":"1","prname":"ABCD","prfhname":"Chevy","Ano":"555"},
{"_id":"1-2","awid":"1","officeid":"1","prname":"bheegi","prfhname":"Henry","Ano":"6555"}]

在这里发布问题之前,您应该检查互联网,无论如何,在C#中有大量有关JSON的资源

https://www.newtonsoft.com/json

使用nuget进行安装

首先创建模型。 比起您可以使用例如Newtonsoft.Json JsonConvert.DeserializeObject<>方法来反序列化json。

static void Main(string[] args)
{
    string json = "[{\"_id\":\"1 - 1\",\"awid\":\"1\",\"officeid\":\"1\",\"prname\":\"ABCD\",\"prfhname\":\"Chevy\",\"Ano\":\"555\"},{ \"_id\":\"1-2\",\"awid\":\"1\",\"officeid\":\"1\",\"prname\":\"bheegi\",\"prfhname\":\"Henry\",\"Ano\":\"6555\"}]";
    var message = JsonConvert.DeserializeObject<Message[]>(json);

    // To see the output (using the for loop as you like ) use this:
    for (int i = 0; i < message.Length; i++)
    {
        Console.WriteLine("_id: " + message[i]._id);
        Console.WriteLine("awid: " + message[i].awid);
        Console.WriteLine("officeid: " + message[i].officeid);
        Console.WriteLine("prname: " + message[i].prname);
        Console.WriteLine("prfhname: " + message[i].prfhname);
        Console.WriteLine("Ano: " + message[i].Ano);
        Console.WriteLine();
    }
    Console.Read();
}

class Message
{
    public string _id { get; set; }
    public string awid { get; set; }
    public string officeid { get; set; }
    public string prname { get; set; }
    public string prfhname { get; set; }
    public string Ano { get; set; }
}

输出:

_id: 1 - 1
awid: 1
officeid: 1
prname: ABCD
prfhname: Chevy
Ano: 555

_id: 1-2
awid: 1
officeid: 1
prname: bheegi
prfhname: Henry
Ano: 6555

暂无
暂无

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

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