如何解析该 json 响应?[关闭]
-
02-01-2020 - |
题
我厌倦了解析 json 响应:
我为模型准备了一些东西:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Announcements
{
public class Private
{
public string created_at { get; set; }
public int id { get; set; }
public string text { get; set; }
public string title { get; set; }
public string updated_at { get; set; }
public int user_id { get; set; }
}
public class User
{
public string first_name { get; set; }
public int id { get; set; }
public string last_name { get; set; }
}
public class Public
{
public string created_at { get; set; }
public int id { get; set; }
public string text { get; set; }
public string title { get; set; }
public User user { get; set; }
}
public class RootObject
{
public List<Private> @private { get; set; }
public List<Public> @public { get; set; }
}
}
现在是时候反序列化响应了:
var tempUsersArray = JsonConvert.DeserializeObject<Announcements.RootObject>(response.Content);
这会导致应用程序崩溃......
有人知道我做错了什么吗?
解决方案
您没有定义班级权限,请更改 class Announcements
到 public class Announcements
. 。现在它应该可以正常工作了,请测试一下这个技巧。
不隶属于 StackOverflow