ошибка при разборе файла json - PullRequest
0 голосов
/ 20 января 2020

я пытаюсь извлечь данные из файла json, полученного из web.i я использовал библиотеку newtonsoft, я использую этот код:

Dim JSONtxt As String = File.ReadAllText("c:\temp\prova.json")
Dim account As Person = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Person)(JSONtxt)

класс:

Public Class Person
    Public Property validationType As String
    Public Property lastName As String
    Public Property firstName As String
End Class

к сожалению аккаунт не получает никакого значения .... как может быть ?? спасибо за помощь

это мой json:

{"listReservationReport":[{"validationType":"PRESENTE","bookingId":"xxxxx","travelId":null,"travelSolutionId":null,"couponId":"xxxxxx","transportMeanName":"aereo","transportClassification":"az","transportMeanDate":"16-01-2020","couponServiceType":"Posto a sedere","materializationType":"NON MATERIALIZZATO","fila":"6","seat":"2A","pnrCode":"xxxxxx","departureLocationName":"NAPOLI capodichino","arrivalLocationName":"ROMA fiumicino","cpCode":"xxxxxxx","offerName":"Super Economy","serviceLevel":"2° Premium","amount":"109,90","adults":1,"teens":0,"alreadyPaied":"--","alreadyCached":"--","ci204":"PRESENTE","firstName":"xxxxxxxx","lastName":"xxxxxx","channelName":"Internet B2C","gender":"Non disponibile","saleSystem":"galileo","travellerInfo":null,"validation":null},{"validationType":"PRESENTE","bookingId":"xxxxx","travelId":null,"travelSolutionId":null,"couponId":"xxxxxx","transportMeanName":"aereo","transportClassification":"az","transportMeanDate":"16-01-2020","couponServiceType":"Posto a sedere","materializationType":"NON MATERIALIZZATO","fila":"6","seat":"2A","pnrCode":"xxxxxx","departureLocationName":"NAPOLI capodichino","arrivalLocationName":"ROMA fiumicino","cpCode":"xxxxxxx","offerName":"Super Economy","serviceLevel":"2° Premium","amount":"109,90","adults":1,"teens":0,"alreadyPaied":"--","alreadyCached":"--","ci204":"PRESENTE","firstName":"xxxxxxxx","lastName":"xxxxxx","channelName":"Internet B2C","gender":"Non disponibile","saleSystem":"galileo","travellerInfo":null,"validation":null},{"validationType":"PRESENTE","bookingId":"xxxxx","travelId":null,"travelSolutionId":null,"couponId":"xxxxxx","transportMeanName":"aereo","transportClassification":"az","transportMeanDate":"16-01-2020","couponServiceType":"Posto a sedere","materializationType":"NON MATERIALIZZATO","fila":"6","seat":"2A","pnrCode":"xxxxxx","departureLocationName":"NAPOLI capodichino","arrivalLocationName":"ROMA fiumicino","cpCode":"xxxxxxx","offerName":"Super Economy","serviceLevel":"2° Premium","amount":"109,90","adults":1,"teens":0,"alreadyPaied":"--","alreadyCached":"--","ci204":"PRESENTE","firstName":"xxxxxxxx","lastName":"xxxxxx","channelName":"Internet B2C","gender":"Non disponibile","saleSystem":"galileo","travellerInfo":null,"validation":null}],"validatorList":[{"firstName":"xxxxx","lastName":"xxxx","roleId":"USR","enterpriseRoleType":"CST"},{"firstName":"xxxx ","lastName":"xxxx ","roleId":"xxx","enterpriseRoleType":"CT"},{"firstName":"x","lastName":"xxxx ","roleId":"USR","enterpriseRoleType":"CPV"},{"firstName":"xxx","lastName":"xxx","roleId":"USR","enterpriseRoleType":"CT"}],"materializedStatus":[{"onboard":30,"absent":0,"none":1,"defect":0,"undo":0}],"notMaterializedStatus":[{"onboard":522,"absent":0,"none":110,"defect":0,"undo":0}]}

1 Ответ

0 голосов
/ 21 января 2020

Хорошо, попробуй ....

Imports System.Linq
Imports BVSoftware.Bvc5.Core
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Imports System.IO
Imports System.Collections.ObjectModel

Partial Class _testPW22
    Inherits System.Web.UI.Page

    Private Class Person
        Public Property validationType As String
        Public Property lastName As String
        Public Property firstName As String
    End Class

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

        Dim JSONtxt As String = File.ReadAllText("c:\temp\prova.json")
        Dim ob As JObject = JObject.Parse(JSONtxt)

        Dim persons As New Collection(Of Person)()

        For Each item As JObject In ob.SelectToken("listReservationReport")
            Dim test As Person = JsonConvert.DeserializeObject(Of Person)(item.ToString())
            persons.Add(test)
        Next

    End Sub

End Class
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...