我想知道如何从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
NB :
如果我别无选择,我将手动创建我的课程……:-(
预先感谢您的帮助
Eric
由于您正在谈论XML和JSON文件,因此建议您安装WebTools 2012.2。
这为Visual Studio添加了一个不错的新功能:
将JSON粘贴为.NET类。使用此特殊粘贴命令将JSON粘贴 到C#或VB.NET代码文件中,Visual Studio将自动生成 从JSON推断的.NET类。
If you have e.g.
在剪贴板中,它将为您生成此类:
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