反序列化 json 对象 xamarin android c# [英] Deserialize json object xamarin android c#

查看:24
本文介绍了反序列化 json 对象 xamarin android c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对反序列化 json 对象没有什么问题.我来自 http url 的 json:

I have little issue with deserialize json object. My json from http url:

我下载的 JSON 的屏幕

我不知道如何反序列化以动态创建按钮.我想出了如何使用文本创建按钮,但我不知道如何使用他们拥有的选项来制作它们.我尝试在 Windows 窗体应用程序中获取这些选项进行测试,但应用程序会崩溃.谢谢你的帮助.

I don't know how to deserialize to make dynamically creating buttons. I figure out how to create buttons with text, but I don't know how to make them with options that they have. I try to get these options in Windows Form app for test, but app will crash. Thank you for help.

推荐答案

你的类应该是这样的:

public class Type
{
    public int id { get; set; }
    public string name { get; set; }
    public bool closedQuestion { get; set; }
    public bool multiAnswer {get; set;}
    public bool usesImage {get; set; }
}
public class RootObject
{
    public int id { get; set; }
    public string name { get; set; }
    public Type type { get; set; }
    public List<string> options { get; set; }
}

然后你应该能够使用 Newtonsoft.Json 反序列化你的 json:

Then you should be able to deserialize your json, using Newtonsoft.Json:

List<RootObject> myData = JsonConvert.DeserializeObject<List<RootObject>>(json);

这篇关于反序列化 json 对象 xamarin android c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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