none
json nested value RRS feed

  • Question

  • hello yet again 

    i have a problem with a json string although i made a lot of research i can't get the values i need

    here is the json string i get as a responce 

    {"Customers":[
    
    {"Id":"35f8d0f4-d866-4b88-932b-51ccf69d787b",
    "Number":"632",
    "Title":null,
    "Gender":null,
    "FirstName":"Stavros",
    "LastName":"Andrianopoulos",
    "SecondLastName":null,"NationalityCode":"GR",
    "LanguageCode":"el-GR",
    "BirthDate":null,
    "BirthPlace":null,
    "CitizenNumber":null,
    "MotherName":null,
    "FatherName":null,
    "Occupation":null,
    "Email":null,
    "Phone":"2109319551",
    "TaxIdentificationNumber":null,
    "LoyaltyCode":null,
    "Notes":null,
    "CreatedUtc":"2017-01-25T11:18:05Z",
    "UpdatedUtc":"2017-01-25T11:18:05Z",
    "Passport":null,
    "IdentityCard":null,
    "Visa":null,
    "DriversLicense":null,
    "Address":{"Line1":"6 Efesou Str.",
    			"Line2":null,"City":"Athens",
    			"PostalCode":"171 21",
    			"CountryCode":"GR",
    			"CountrySubdivisionCode":null},
    			"Classifications":[],
    			"Options":[],
    			"CategoryId":null,
    			"BirthDateUtc":null},
    
    {"Id":"73a3afdc-7e2b-4ff3-b030-644119ea5053",
    "Number":"636",
    "Title":"Mister",
    "Gender":"Male",
    "FirstName":"Pavlos",
    "LastName":"Sideris",
    "SecondLastName":null,
    "NationalityCode":"GR",
    "LanguageCode":"el-GR",
    "BirthDate":"1979-10-23",
    "BirthPlace":"Αθήνα ",
    "CitizenNumber":null,
    "MotherName":null,
    "FatherName":null,
    "Occupation":null,
    "Email":"pavlos@yahoo.gr",
    "Phone":"2286041232",
    "TaxIdentificationNumber":"",
    "LoyaltyCode":null,
    "Notes":null,
    "CreatedUtc":"2017-01-27T10:36:24Z",
    "UpdatedUtc":"2017-01-27T10:42:45Z",
    "Passport":null,
    "IdentityCard":null,
    "Visa":null,
    "DriversLicense":null,"Address":
    		{"Line1":"Χώρα ",
    		"Line2":"",
    		"City":"Φολέγανδρος",
    		"PostalCode":"84011",
    		"CountryCode":"GR",
    		"CountrySubdivisionCode":null},
    		"Classifications":[],
    		"Options":[],
    		"CategoryId":null,
    		"BirthDateUtc":"1979-10-23T12:00:00Z"},
    
    {"Id":"8d97bfe3-c30e-4a8e-8f2b-68bc5133f9d4",
    "Number":"629",
    "Title":"Miss",
    "Gender":"Female",
    "FirstName":"MARTHA",
    "LastName":"MARTHA",
    "SecondLastName":null,
    "NationalityCode":"GR",
    "LanguageCode":"el-GR",
    "BirthDate":null,
    "BirthPlace":null,
    "CitizenNumber":null,
    "MotherName":null,
    "FatherName":null,
    "Occupation":null,
    "Email":null,
    "Phone":null,
    "TaxIdentificationNumber":null,
    "LoyaltyCode":null,
    "Notes":null,
    "CreatedUtc":"2017-01-16T13:26:01Z",
    "UpdatedUtc":"2018-06-03T13:08:51Z",
    "Passport":null,
    "IdentityCard":null,
    "Visa":null,
    "DriversLicense":null,
    "Address":{"Line1":null,
    				"Line2":null,
    				"City":null,
    				"PostalCode":null,
    				"CountryCode":null,
    				"CountrySubdivisionCode":null},
    				"Classifications":["Returning"],
    				"Options":[],
    				"CategoryId":null,
    				"BirthDateUtc":null},
    
    {"Id":"70a8cee5-2855-4de1-a4b9-923113b1ceeb",
    "Number":"634",
    "Title":"Miss",
    "Gender":"Female",
    "FirstName":"Maria",
    "LastName":"Papadopoulou",
    "SecondLastName":null,"
    "NationalityCode":null,
    "LanguageCode":null,
    "BirthDate":null,
    "BirthPlace":null,
    "CitizenNumber":null,
    "MotherName":null,
    "FatherName":null,
    "Occupation":null,
    "Email":null,
    "Phone":null,
    "TaxIdentificationNumber":null,
    "LoyaltyCode":null,
    "Notes":null,
    "CreatedUtc":"2017-01-26T18:15:13Z",
    "UpdatedUtc":"2017-01-26T18:15:13Z",
    "Passport":null,
    "IdentityCard":null,
    "Visa":null,
    "DriversLicense":null,
    	"Address":{"Line1":null,
    				"Line2":null,
    				"City":null,
    				"PostalCode":null,
    				"CountryCode":null,
    				"CountrySubdivisionCode":null},
    				"Classifications":[],
    				"Options":[],
    				"CategoryId":null,
    				"BirthDateUtc":null},
    
    {"Id":"a6f4fc48-cb4d-4dc6-b40e-a2cca8ea86be",
    "Number":"630",
    "Title":null,
    "Gender":null,
    "FirstName":"Corrections",
    "LastName":"House Use",
    "SecondLastName":null,
    "NationalityCode":null,
    "LanguageCode":null,
    "BirthDate":null,
    "BirthPlace":null,
    "CitizenNumber":null,
    "MotherName":null,
    "FatherName":null,
    "Occupation":null,
    "Email":null,
    "Phone":null,
    "TaxIdentificationNumber":null,
    "LoyaltyCode":"",
    "Notes":"den tou arese to maxilari ",
    "CreatedUtc":"2017-01-20T11:23:58Z",
    "UpdatedUtc":"2018-02-27T14:21:30Z",
    "Passport":null,
    "IdentityCard":null,
    "Visa":null,
    "DriversLicense":null,
    	"Address":{"Line1":null,
    				"Line2":null,
    				"City":null,
    				"PostalCode":null,
    				"CountryCode":null,
    				"CountrySubdivisionCode":null},
    				"Classifications":["Problematic"],
    				"Options":[],
    				"CategoryId":null,
    				"BirthDateUtc":null},
    				
    {"Id":"82043dca-1cff-4d16-b064-aca85da84144",
    "Number":"627",
    "Title":"Misses",
    "Gender":"Female",
    "FirstName":"ANASTASIA",
    "LastName":"ATHANASIADOU",
    "SecondLastName":null,
    "NationalityCode":"GR",
    "LanguageCode":"el-GR",
    "BirthDate":null,
    "BirthPlace":null,
    "CitizenNumber":null,
    "MotherName":null,
    "FatherName":null,
    "Occupation":null,
    "Email":"fgdgdf@gmail.com",
    "Phone":null,
    "TaxIdentificationNumber":null,
    "LoyaltyCode":null,
    "Notes":null,
    "CreatedUtc":"2017-01-13T10:58:13Z",
    "UpdatedUtc":"2017-01-13T10:58:13Z",
    "Passport":null,
    "IdentityCard":null,
    "Visa":null,
    "DriversLicense":null,
    	"Address":{"Line1":null,
    				"Line2":null,
    				"City":null,
    				"PostalCode":null,
    				"CountryCode":null,
    				"CountrySubdivisionCode":null},
    				"Classifications":[],
    				"Options":[],
    				"CategoryId":null,
    				"BirthDateUtc":null},
    				
    {"Id":"aa6075a4-7dde-4609-a4ab-ef741dcc7ceb",
    "Number":"628",
    "Title":null,
    "Gender":null,
    "FirstName":"Nikos ",
    "LastName":"Giourou",
    "SecondLastName":null,
    "NationalityCode":null,
    "LanguageCode":null,
    "BirthDate":null,
    "BirthPlace":null,
    "CitizenNumber":null,
    "MotherName":null,
    "FatherName":null,
    "Occupation":null,
    "Email":null,
    "Phone":null,
    "TaxIdentificationNumber":null,
    "LoyaltyCode":null,
    "Notes":null,
    "CreatedUtc":"2017-01-16T10:46:29Z",
    "UpdatedUtc":"2017-01-16T10:46:29Z",
    "Passport":null,
    "IdentityCard":null,
    "Visa":null,
    "DriversLicense":null,
    	"Address":{"Line1":null,
    				"Line2":null,
    				"City":null,
    				"PostalCode":null,
    				"CountryCode":null,
    				"CountrySubdivisionCode":null},
    				"Classifications":[],
    				"Options":[],
    				"CategoryId":null,
    				"BirthDateUtc":null},
    
    {"Id":"d670a726-c5d2-4ec2-bca7-faad98c323d4",
    "Number":"637",
    "Title":"Miss",
    "Gender":"Female",
    "FirstName":"Παναγιώτα",
    "LastName":"Χαιδεμένου ",
    "SecondLastName":null,
    "NationalityCode":"GR",
    "LanguageCode":"el-GR",
    "BirthDate":null,
    "BirthPlace":null,
    "CitizenNumber":null,
    "MotherName":null,
    "FatherName":null,
    "Occupation":null,
    "Email":"pan.ch@yahoo.gr",
    "Phone":null,
    "TaxIdentificationNumber":null,
    "LoyaltyCode":null,
    "Notes":null,
    "CreatedUtc":"2017-01-27T11:10:33Z",
    "UpdatedUtc":"2017-01-27T11:10:33Z",
    "Passport":null,
    "IdentityCard":null,
    "Visa":null,
    "DriversLicense":null,
    	"Address":{"Line1":null,
    				"Line2":null,
    				"City":null,
    				"PostalCode":null,
    				"CountryCode":null,
    				"CountrySubdivisionCode":null},
    				"Classifications":[],
    				"Options":[],
    				"CategoryId":null,
    				"BirthDateUtc":null},
    
    {"Id":"a266e8e6-3a6a-4e6c-8a07-ffeb24973cee",
    "Number":"631",
    "Title":null,
    "Gender":null,
    "FirstName":"Stavros",
    "LastName":"Andrianopoulos",
    "SecondLastName":null,
    "NationalityCode":"GR",
    "LanguageCode":"el-GR",
    "BirthDate":null,
    "BirthPlace":null,
    "CitizenNumber":null,
    "MotherName":null,
    "FatherName":null,
    "Occupation":null,
    "Email":null,
    "Phone":"2109319551",
    "TaxIdentificationNumber":null,
    
    "LoyaltyCode":"",
    
    "Notes":"extra pillow",
    "CreatedUtc":"2017-01-25T10:13:07Z",
    "UpdatedUtc":"2018-02-21T08:40:00Z",
    "Passport":null,
    "IdentityCard":null,
    "Visa":null,
    "DriversLicense":null,
    	"Address":{"Line1":"6 Efesou Str.",
    				"Line2":null,
    				"City":"Athens",
    				"PostalCode":"171 21",
    				"CountryCode":"GR",
    				"CountrySubdivisionCode":null},
    				"Classifications":[],
    				"Options":[],
    				"CategoryId":null,
    				"BirthDateUtc":null}]}

    what i need is the id and classification 
    this is the code that i use to get the id 

    'strResponse has the json string from above
    
    dim json as JObject  = JObject .Parse(strResponce)
    
    dim commToken as Jtoken 
    
    dim commValue as string 
    
    for each row in json ("Costumers")
    
    commToken = row("Id")
    
    commValue = DirectCast(CommToken,JValue).value 
    
    next
    

    now what i need is the classifications 

    i have tried a lot of things but nothing worked plz any help will really helpfull

    Monday, September 10, 2018 9:00 AM

All replies

  • Hi

    Please check:

    "FirstName":"Maria",
    "LastName":"Papadopoulou",
    "SecondLastName":null,"

    the trailing double quote character after the :Null, seems to be incorrect.

    If I remove that trailing character, I can read all the Tokens correctly.


    Regards Les, Livingston, Scotland


    • Edited by leshay Monday, September 10, 2018 10:41 AM
    Monday, September 10, 2018 10:39 AM
  • that is propablly my mistake as i was trying the json string more readable 

    but still the problem is not the first value but the nested value in the adress 
    which if am not mistaken is a list 
    • Edited by Ipodamia Monday, September 10, 2018 10:44 AM
    Monday, September 10, 2018 10:42 AM
  • Looks to me that you have a Json array of objects.

    dim customers = JArray.Parse(strResponce)

    for each obj in customers

        dim id = obj.iD

    next

    What you are using is late binding that means you won't be able to intellisensed properties on the obj properties.

    What you should do is debug breakpoint at the for each statement and use Quickwatch to see what is inside customers, becuase obj.properties as you seem them in customers is case sensitive.  

    Or you can make a custom object that matches the object in the json array  and you could do this. .

      dim dtoprojects = new List(Of DtoProject)
      dim json  = webclient.DownloadString(url)
      Dim projects = JsonConvert.DeserializeObject(of List(Of DtoProject))(json)
      dtoprojects = projects
    
    for each dto as DtoProject in dtoprojects
         dim projected = dto.ProjectId
    next
    
    =================================================
    
    Public Class DtoProject
    
        Public Property ProjectId As Int32
        Public Property ClientName As String
        Public Property ProjectName As String
        Public Property Technology As String
        Public Property ProjectType As String
        Public Property UserId As String
        Public Property StartDate  As DateTime
        Public Property EndDate As DateTime? 
        Public Property Cost As Decimal
       
    End Class

    Monday, September 10, 2018 10:44 AM
  • i can get the id 

    what i haven't been able to get is the classificationwhich is a nested value 

    Monday, September 10, 2018 11:04 AM
  • There is nothing in Classification which is an array within an array based on the Jason you have posted.

    And I still contend that it would be easier to me if you walked the dynamic json array in a for each loop using late binding.

    Monday, September 10, 2018 11:29 AM