使用C#将Treeview转换为JSON [英] Convert a Treeview to JSON using C#

查看:1544
本文介绍了使用C#将Treeview转换为JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用C#将TreeView对象转换为JSON.我当前正在使用JsonConvert.SerializeObject().

I have to convert a TreeView object to JSON using C#. I am currently using JsonConvert.SerializeObject().

public class SubTreeNode : TreeNode
{
    public CustomProperties customProperties;
}

public class CustomProperties
{

    public string property1 = "Property1";
    public string property2 = "Property2";
    public string property3 = "Property3";
}

在使用JsonConvert.SerializeObject(treeView1.Nodes);进行尝试时,它仅返回顶部节点,而不返回子节点,子子节点,依此类推.

When tried it with JsonConvert.SerializeObject(treeView1.Nodes); it only returned the top nodes... not the child nodes, sub-child, and so on.

对该TreeView对象进行序列化和反序列化的最简单方法是什么?

What is the easiest way to serialize and deserialize this TreeView object?

推荐答案

您将需要添加递归地从每个节点生成JSON的方法.

You will need to add methods that produce JSON from each node recursively.

查看相关文章:将树序列化为Json Object .

这篇关于使用C#将Treeview转换为JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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