gpt4 book ai didi

xml - 如何从 json 文件(或 xml 文件)创建 vb.net 对象类

转载 作者:数据小太阳 更新时间:2023-10-29 01:53:16 26 4
gpt4 key购买 nike

我想知道如何从 json 文件或 xml 文件创建对象类?

例子:

我从 webservice 得到这个 json 文件:

{"nid":"3798","vid":"3788","type":"contact","language":"fr","title":"G","uid":"1","status":"1","created":"1374598689","changed":"1374598689","comment":"1","promote":"0","sticky":"0","tnid":"0","translate":"0"}

我想创建一个类:

Public Class Card
Public nid As Integer
Public vid As Integer
Public type As String
Public language As String
Public title As String
.
.
.
End Class

注意:

  • 我的问题不是如何在 vb.net 中序列化/反序列化 json 对象?
  • 我的 xml 文件没有 XSD 那为什么更难
  • 我的代码是用 VB.Net 而非 C# 编写的。我发现很多网站将 json 转换为 c# ( http://json2csharp.com/ ),但没有将 json 转换为 vb.net

如果我别无选择,我将手动创建我的类...... :-(

预先感谢您的帮助

埃里克

最佳答案

既然你在谈论 XML 和 JSON 文件,我建议你安装 Web Tools 2012.2 .

这为 Visual Studio 添加了一个不错的新功能:

Paste JSON as a .NET class. Using this Special Paste command to paste JSON into a C# or VB.NET code file, and Visual Studio will automatically generate .NET classes inferred from the JSON.

enter image description here

如果你有

{"nid":"3798","vid":"3788","type":"contact","language":"fr","title":"G","uid":"1","status":"1","created":"1374598689","changed":"1374598689","comment":"1","promote":"0","sticky":"0","tnid":"0","translate":"0"}

在你的剪贴板中,它会为你生成这个类:

Public Class Rootobject
Public Property nid As String
Public Property vid As String
Public Property type As String
Public Property language As String
Public Property title As String
Public Property uid As String
Public Property status As String
Public Property created As String
Public Property changed As String
Public Property comment As String
Public Property promote As String
Public Property sticky As String
Public Property tnid As String
Public Property translate As String
End Class

关于xml - 如何从 json 文件(或 xml 文件)创建 vb.net 对象类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22528884/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com