如何从json文件(或xml文件)创建vb.net对象类 [英] How to create vb.net object class from json file (or xml file)

查看:296
本文介绍了如何从json文件(或xml文件)创建vb.net对象类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm wondering how to create a objet class from json file or xml file ?

示例:

我从网络服务获得了这个json文件:

I get this json file from webservice :

{"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"}

我想创建一个像这样的类:

I would like to create a class like :

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:

  • 我的问题不是如何在vb.net中序列化/反序列化json objet吗?
  • 我的xml文件没有XSD,这为什么会更困难
  • 我的代码是用VB.Net而不是C#编写的.我发现许多网站将json转换为c#( http://json2csharp.com/),但没有将json转换为vb.网
  • My question is not how to serialize / deserialize json objet in vb.net ?
  • My xml file doesn't have XSD that why is more difficult
  • My code is written in VB.Net not in C#. I found many website which convert json to c# (http://json2csharp.com/), but nothing json to vb.net

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

If I have no choice I will create manually my classes ... :-(

提前感谢您的帮助

埃里克

推荐答案

由于您正在谈论XML和JSON文件,因此建议您安装

Since you're talking about XML and JSON files, I recommend you to install Web Tools 2012.2.

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

This adds a nice new feature to Visual Studio:

将JSON粘贴为.NET类.使用此特殊粘贴命令将JSON粘贴到C#或VB.NET代码文件中,Visual Studio将自动生成从JSON推断的.NET类.

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.

如果有

{"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"}

在剪贴板中,它将为您生成此类:

in your clipboard, it will generate this class for you:

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

这篇关于如何从json文件(或xml文件)创建vb.net对象类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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