Vb.net код для разбора файла .json
дорогие члены,
Может ли кто - нибудь помочь мне с кодом для разбора json - файла через vb.net код.
Что я уже пробовал:
ноль опыта в JSON
Эта статья даст вам инструменты и покажет, как это сделать: Работа с JSON в C# и VB[^]
** ОБНОВЛЕНИЕ **
Ваш JSON недействителен, и вы можете проверить его здесь: JSON Formatter & валидатор[^] (ссылка приведена в статье ссылка выше)
Правильный JSON-это:
{ "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 } } } } } } } } }
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 <Json
спасибо, что сработало..... Реальность такова, что я должен был бы правильно прочитать вашу статью, но я открыл ее на своем мобильном телефоне, и она просто открылась до "вводной части", сегодня я открыл ее на своем компьютере и прочитал до конца.....
Благодарить вас недостаточно, но в любом случае большое спасибо..........
Вы можете использовать Newtonsoft для чтения json - файла
imports Newtonsoft.Json.Linq dim myJObject = JObject.Parse(file) Console.WriteLine(myJObject.SelectToken("key"))
Console.WriteLine(myJObject.SelectToken("properties"))
Console.WriteLine(myJObject.SelectToken("properties.gstin.maxLength"))