用于解析.json文件的Vb.net代码 [英] Vb.net code to parse .json file
问题描述
亲爱的会员,
任何人都可以帮我解决通过vb.net代码解析json文件的代码。
我尝试了什么:
json中的零exp
本文将为您提供工具并向您展示如何:工作在C#中使用JSON& VB [ ^ ]
**更新**
您的JSON无效,您可以查看它在这里: JSON Formatter&验证器 [ ^ ](上面文章链接中提供的链接)
正确的JSON是:
{
type:object ,
properties:{
gstin:{
description:纳税人的GSTIN,
type:string ,
maxLength:15,
minLength:15,
模式:^ [a-zA-Z0-9] +
< blockquote>,
required:true
},
ret_pd:{
description:Return Period,
type: string,
required:true
},
checksum:{
description:Invoice Check sum value,
type: string,
required:true
},
ttl_inv:{
description:总税额,
类型: number,
required:true
},
ttl_tax:{
description:总税额,
类型:数字,
必需:真
},
ttl_igst:{
description:总IGST金额,
类型:数字,
必需:真
},
ttl_sgst:{
description:总SGST金额,
类型:数字,
必需:真
},
ttl_cgst:{
description:总CGST金额,
类型:数字,
必需:真
},
sec_sum:{
type:array,
items:{
type:object,
properties: {
sec_nm:{
description:Return Section,
type:string,
required:true
},
checksum:{
description:发票支票金额,
type:string,
required:true
},
ttl_inv:{
description:总税额,
type:number,
required:true
},
ttl_tax:{
description:总税额,
type:number,
required:true
},
ttl_igst:{
description:总IGST金额,
类型:数字,
required:true
},
ttl_sgst:{
description:总SGST金额,
type:number,
required:true
},
ttl_cgst:{
description:总CGST金额,
type:number,
required:true
},
cpty_sum:{
type:array,
items:{
type: OBJE ct,
properties:{
ctin:{
description:纳税人的CTIN,
type:string,
maxLength:15,
minLength:15,
pattern:^ [a-zA-Z0-9] +
,
required:true
},
checksum:{
description:发票支票金额,
type:string ,
required:true
},
ttl_inv:{
description:总税额,
type:number ,
required:true
},
ttl_tax:{
description:总税额,
type:number ,
required:true
},
ttl_igst:{
description:IGST总额,
type:number ,
required:true
},
ttl_sgst:{
description:总SGST金额,
类型:数字,
必需:真
},
ttl_cgst:{
description:总CGST金额,
类型:数字,
必需:真
}
}
}
}
}
}
}
}
}
现在您可以使用以下方法生成课程: JSON Utils:生成C#,VB.Net,SQL表,来自JSON的Java和PHP [ ^ ](上面文章链接中提供的链接) )
以下是生成的类:
公开 类 Gstin
< JsonProperty( 描述跨度>)GT;
公开 属性描述 As 字符串
< JsonProperty( 型跨度>)GT;
公开 属性类型作为 字符串
< JsonProperty( 最大长度跨度>)GT;
公开 属性 MaxLength 作为 整数
< JsonProperty( 的minLength跨度>)GT;
公开 属性 MinLength 作为 整数
< JsonProperty( 图案跨度>)GT;
公开 属性模式作为 字符串
< JsonProperty( 必需的跨度>)GT;
公开 属性必需作为 布尔
结束 类
公共 类 RetPd
< JsonProperty( description)>
公开 属性描述 As 字符串
< JsonProperty( 型跨度>)GT;
公开 属性类型作为 字符串
< JsonProperty( 必需的跨度>)GT;
公开 属性必需作为 布尔
结束 类
公共 类校验和
< JsonProperty( description)>
公开 属性描述 As 字符串
< JsonProperty( 型跨度>)GT;
公开 属性类型作为 字符串
< JsonProperty( 必需的跨度>)GT;
公开 属性必需作为 布尔
结束 类
公共 类 TtlInv $ b
$ b< JsonProperty( description)>
公开 属性描述 As 字符串
< JsonProperty( 型跨度>)GT;
公开 属性类型作为 字符串
< JsonProperty( 必需的跨度>)GT;
公开 属性必需作为 布尔
结束 类
公共 类 TtlTax
< JsonProperty( description)>
公开 属性描述 As 字符串
< JsonProperty( 型跨度>)GT;
公开 属性类型作为 字符串
< JsonProperty( 必需的跨度>)GT;
公开 属性必需作为 布尔
结束 类
公共 类 TtlIgst
< JsonProperty( description)>
公开 属性描述 As 字符串
< JsonProperty( 型跨度>)GT;
公开 属性类型作为 字符串
< JsonProperty( 必需的跨度>)GT;
公开 属性必需作为 布尔
结束 类
公共 类 TtlSgst
< JsonProperty( description)>
公开 属性描述 As 字符串
< JsonProperty( 型跨度>)GT;
公开 属性类型作为 字符串
< JsonProperty( 必需的跨度>)GT;
公开 属性必需作为 布尔
结束 类
公共 类 TtlCgst
< JsonProperty( description)>
公开 属性描述 As 字符串
< JsonProperty( 型跨度>)GT;
公开 属性类型作为 字符串
< JsonProperty( 必需的跨度>)GT;
公开 属性必需作为 布尔
结束 类
公共 类 SecNm
< JsonProperty( description)>
公开 属性描述 As 字符串
< JsonProperty( 型跨度>)GT;
公开 属性类型作为 字符串
< JsonProperty( 必需的跨度>)GT;
公开 属性必需作为 布尔
结束 类
公共 类 Ctin
< JsonProperty( description)>
公开 属性描述 As 字符串
< JsonProperty( 型跨度>)GT;
公开 属性类型作为 字符串
< JsonProperty( 最大长度跨度>)GT;
公开 属性 MaxLength 作为 整数
< JsonProperty( 的minLength跨度>)GT;
公开 属性 MinLength 作为 整数
< JsonProperty( 图案跨度>)GT;
公开 属性模式作为 字符串
< JsonProperty( 必需的跨度>)GT;
公开 属性必需作为 布尔
结束 类
公共 类属性
< JsonProperty( ctin)>
公开 属性 Ctin 作为 Ctin
< JsonProperty( checksum)>
公开 属性校验和作为
< JsonProperty( ttl_inv)>
公开 属性 TtlInv 作为
< JsonProperty( ttl_tax)>
公开 属性 TtlTax 作为
< JsonProperty( ttl_igst)>
公开 属性 TtlIgst 作为
< JsonProperty( ttl_sgst)>
公开 属性 TtlSgst 作为
< JsonProperty( ttl_cgst)>
公开 属性 TtlCgst 作为
结束 类
公开 类项目
< JsonProperty( type)>
公开 属性类型作为 字符串
< JsonProperty( 属性跨度>)GT;
公开 属性属性作为属性
结束 类
公共 类 CptySum
< JsonProperty( type)>
公开 属性类型作为 字符串
< JsonProperty( 项跨度>)GT;
公开 属性项作为商品
结束 类
公共 类属性
< JsonProperty( sec_nm)>
公共 属性 SecNm 作为 SecNm
< JsonProperty( checksum)>
公开 属性校验和作为
< JsonProperty( ttl_inv)>
公开 属性 TtlInv 作为
< JsonProperty( ttl_tax)>
公开 属性 TtlTax 作为
< JsonProperty( ttl_igst)>
公开 属性 TtlIgst 作为
< JsonProperty( ttl_sgst)>
公开 属性 TtlSgst 作为
< JsonProperty( ttl_cgst)>
公开 属性 TtlCgst 作为
< JsonProperty( cpty_sum)>
公开 属性 CptySum 作为 CptySum
结束 类
公共 类项目
< JsonProperty( type)>
公开 属性类型作为 字符串
< JsonProperty( 属性跨度>)GT;
公开 属性属性作为属性
结束 类
公共 类 SecSum
< JsonProperty( type)>
公开 属性类型作为 字符串
< JsonProperty( 项跨度>)GT;
公开 属性项作为商品
结束 类
公共 类属性
< JsonProperty( gstin)>
公开 属性 Gstin 作为 Gstin
< JsonProperty( ret_pd)>
公开 属性 RetPd 作为 RetPd
< JsonProperty( checksum)>
公开 属性校验和作为校验和
< JsonProperty( ttl_inv)>
公开 属性 TtlInv 作为 TtlInv $ b
$ b< JsonProperty( ttl_tax)>
公开 属性 TtlTax 作为 TtlTax
< JsonProperty( ttl_igst)>
公开 属性 TtlIgst 作为 TtlIgst
< JsonProperty( ttl_sgst)>
公开 属性 TtlSgst 作为 TtlSgst
< JsonProperty( ttl_cgst)>
公开 属性 TtlCgst 作为 TtlCgst
< JsonProperty( sec_sum)>
公共 属性 SecSum 作为 SecSum
结束 类
公共 类示例
< JsonProperty( type)>
公开 属性类型作为 字符串
< JsonProperty( 属性跨度>)GT;
公开 属性属性作为属性
结束 类
现在我们可以将JSON数据反序列化为.Net类[es] :(再次从上面的文章链接中,使用提供的JsonHelper类)
' 从文件中检索JSON数据
Dim rawJson = File.ReadAllText(Path.Combine(filePath,fileName))
' 转换为VB类类型化对象
ggsstt = JsonHelper.ToClass( 示例)(rawJson)
您需要帮助的所有内容都在提供的文章链接中。
Dear Members,
Can anyone please help me with the code to parse json file through vb.net code.
What I have tried:
zero exp in json
This article will give you the tools and show you how: Working with JSON in C# & VB[^]
** UPDATE **
Your JSON is invalid and you can check it here: JSON Formatter & Validator[^] (link provided in the article link above)
Correct JSON is:
{ "type": "object", "properties": { "gstin": { "description":"GSTIN of the taxpayer", "type":"string", "maxLength":15, "minLength":15, "pattern":"^[a-zA-Z0-9]+
", "required":true }, "ret_pd": { "description":"Return Period", "type": "string", "required":true }, "checksum": { "description":"Invoice Check sum value", "type": "string", "required":true }, "ttl_inv": { "description":"total tax amount", "type": "number", "required":true }, "ttl_tax": { "description":"total tax amount", "type": "number", "required":true }, "ttl_igst": { "description":"total IGST amount", "type": "number", "required":true }, "ttl_sgst": { "description":"total SGST amount", "type": "number", "required":true }, "ttl_cgst": { "description":"total CGST amount", "type": "number", "required":true }, "sec_sum": { "type": "array", "items": { "type": "object", "properties": { "sec_nm": { "description":"Return Section", "type": "string", "required":true }, "checksum": { "description":"Invoice Check sum value", "type": "string", "required":true }, "ttl_inv": { "description":"total tax amount", "type": "number", "required":true }, "ttl_tax": { "description":"total tax amount", "type": "number", "required":true }, "ttl_igst": { "description":"total IGST amount", "type": "number", "required":true }, "ttl_sgst": { "description":"total SGST amount", "type": "number", "required":true }, "ttl_cgst": { "description":"total CGST amount", "type": "number", "required":true }, "cpty_sum": { "type": "array", "items": { "type": "object", "properties": { "ctin": { "description":"CTIN of the taxpayer", "type":"string", "maxLength":15, "minLength":15, "pattern":"^[a-zA-Z0-9]+
", "required":true }, "checksum": { "description":"Invoice Check sum value", "type": "string", "required":true }, "ttl_inv": { "description":"total tax amount", "type": "number", "required":true }, "ttl_tax": { "description":"total tax amount", "type": "number", "required":true }, "ttl_igst": { "description":"total IGST amount", "type": "number", "required":true }, "ttl_sgst": { "description":"total SGST amount", "type": "number", "required":true }, "ttl_cgst": { "description":"total CGST amount", "type": "number", "required":true } } } } } } } } }
Now you can generate your classes using: JSON Utils: Generate C#, VB.Net, SQL Table, Java and PHP from JSON[^] (link provided in the article link above)
And here are the classes generated:
Public Class Gstin <JsonProperty("description")> Public Property Description As String <JsonProperty("type")> Public Property Type As String <JsonProperty("maxLength")> Public Property MaxLength As Integer <JsonProperty("minLength")> Public Property MinLength As Integer <JsonProperty("pattern")> Public Property Pattern As String <JsonProperty("required")> Public Property Required As Boolean End Class Public Class RetPd <JsonProperty("description")> Public Property Description As String <JsonProperty("type")> Public Property Type As String <JsonProperty("required")> Public Property Required As Boolean End Class Public Class Checksum <JsonProperty("description")> Public Property Description As String <JsonProperty("type")> Public Property Type As String <JsonProperty("required")> Public Property Required As Boolean End Class Public Class TtlInv <JsonProperty("description")> Public Property Description As String <JsonProperty("type")> Public Property Type As String <JsonProperty("required")> Public Property Required As Boolean End Class Public Class TtlTax <JsonProperty("description")> Public Property Description As String <JsonProperty("type")> Public Property Type As String <JsonProperty("required")> Public Property Required As Boolean End Class Public Class TtlIgst <JsonProperty("description")> Public Property Description As String <JsonProperty("type")> Public Property Type As String <JsonProperty("required")> Public Property Required As Boolean End Class Public Class TtlSgst <JsonProperty("description")> Public Property Description As String <JsonProperty("type")> Public Property Type As String <JsonProperty("required")> Public Property Required As Boolean End Class Public Class TtlCgst <JsonProperty("description")> Public Property Description As String <JsonProperty("type")> Public Property Type As String <JsonProperty("required")> Public Property Required As Boolean End Class Public Class SecNm <JsonProperty("description")> Public Property Description As String <JsonProperty("type")> Public Property Type As String <JsonProperty("required")> Public Property Required As Boolean End Class Public Class Ctin <JsonProperty("description")> Public Property Description As String <JsonProperty("type")> Public Property Type As String <JsonProperty("maxLength")> Public Property MaxLength As Integer <JsonProperty("minLength")> Public Property MinLength As Integer <JsonProperty("pattern")> Public Property Pattern As String <JsonProperty("required")> Public Property Required As Boolean End Class Public Class Properties <JsonProperty("ctin")> Public Property Ctin As Ctin <JsonProperty("checksum")> Public Property Checksum As <JsonProperty("ttl_inv")> Public Property TtlInv As <JsonProperty("ttl_tax")> Public Property TtlTax As <JsonProperty("ttl_igst")> Public Property TtlIgst As <JsonProperty("ttl_sgst")> Public Property TtlSgst As <JsonProperty("ttl_cgst")> Public Property TtlCgst As End Class Public Class Items <JsonProperty("type")> Public Property Type As String <JsonProperty("properties")> Public Property Properties As Properties End Class Public Class CptySum <JsonProperty("type")> Public Property Type As String <JsonProperty("items")> Public Property Items As Items End Class Public Class Properties <JsonProperty("sec_nm")> Public Property SecNm As SecNm <JsonProperty("checksum")> Public Property Checksum As <JsonProperty("ttl_inv")> Public Property TtlInv As <JsonProperty("ttl_tax")> Public Property TtlTax As <JsonProperty("ttl_igst")> Public Property TtlIgst As <JsonProperty("ttl_sgst")> Public Property TtlSgst As <JsonProperty("ttl_cgst")> Public Property TtlCgst As <JsonProperty("cpty_sum")> Public Property CptySum As CptySum End Class Public Class Items <JsonProperty("type")> Public Property Type As String <JsonProperty("properties")> Public Property Properties As Properties End Class Public Class SecSum <JsonProperty("type")> Public Property Type As String <JsonProperty("items")> Public Property Items As Items End Class Public Class Properties <JsonProperty("gstin")> Public Property Gstin As Gstin <JsonProperty("ret_pd")> Public Property RetPd As RetPd <JsonProperty("checksum")> Public Property Checksum As Checksum <JsonProperty("ttl_inv")> Public Property TtlInv As TtlInv <JsonProperty("ttl_tax")> Public Property TtlTax As TtlTax <JsonProperty("ttl_igst")> Public Property TtlIgst As TtlIgst <JsonProperty("ttl_sgst")> Public Property TtlSgst As TtlSgst <JsonProperty("ttl_cgst")> Public Property TtlCgst As TtlCgst <JsonProperty("sec_sum")> Public Property SecSum As SecSum End Class Public Class Example <JsonProperty("type")> Public Property Type As String <JsonProperty("properties")> Public Property Properties As Properties End Class
Now we can deserialize the JSON data into .Net class[es]: (Again from the article link above, using the JsonHelper class provided)
' Retrieve JSON data from file Dim rawJson = File.ReadAllText(Path.Combine(filePath, fileName)) ' Convert to VB Class typed object ggsstt = JsonHelper.ToClass(Of Example)(rawJson)
Everything tht you needed to help you was in the article link provided.
这篇关于用于解析.json文件的Vb.net代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!