I need to read this string
{
“patient”: {
“id”: “PZ001”,
“surname”: “Rossi”,
“name”: “Mario”,
“sex”: “M”,
“date_of_birth”: “1985-04-04”
},
“anthropometry”: {
“height_cm”: 178,
“weight_kg”: 82,
“wrist_circumference_cm”: 17,
“waist_circumference_cm”: 95,
“hip_circumference_cm”: 102,
“neck_circumference_cm”: 40
}
But I can’t with the code below.
I can read the first part if I change it to an array like this.
[
{
“id”: “PZ001”,
“surname”: “Rossi”,
“name”: “Mario”,
“sex”: “M”,
“date_birth”: “1985-04-04”
}
]
For the code, I created a class called patient with
the properties surname, date_of_birth, id, name, and sex
and an anthropometry class with the related properties,
two sub
json2Patients(j as JSONItem) as patient()
dim result() as patient
For c as Integer = 0 to j.Count-1
dim jChild as JSONItem = j.Child(c)
dim p as patient = patientJ2O(jChild)
if p<>nil then result.Append(p)
Next
Return result
patientJ2O(j as JSONItem) as patient
dim p as new patient
p.id = j.Lookup(“id”,“”)
p.Surname = j.Lookup(“surname”,“”)
p.Name = j.Lookup(“name”,“”)
p.BirthDate = j.Lookup(“birthdate”,“”)
p.sex = j.Lookup(“sex”,“”)
'dim jAnth as JSONItem = j.Lookup(“anthropometry”, new JSONItem)
'dim anth as new anthropometry
'anth.height = jAnth.Lookup(“height_cm”, 0)
'anth.weight = jAnth.Lookup(“weight_kg”, 0)
'anth.wrist = jAnth.Lookup(“wrist_cm”, 0)
'anth.waist = jAnth.Lookup(“waist_cm”, 0)
'anth.hips = jAnth.Lookup(“hip_cm”, 0)
'anth.neck = jAnth.Lookup(“neck_cm”, 0)
This part is not enabled, it gives me an error
Return p
for reading this code
dim restUrl as String = “https://xxxxxxxxx.php”
dim response As String
dim username as String = userrest
dim password as String = passwrest
dim socket as new HTTPSocket
dim timeout as Integer = 30
'socket.SetRequestHeader(“Authorization”, “Basic " + EncodeBase64(username+”:"+password))
'response = socket.get(RestUrl, timeout)
I don’t use the downloaded one for testing
response =textrest.text
response = DefineEncoding(response, Encodings.UTF8)
dim cl as Integer
dim j As New JSONItem(response)
j.Compact = False
patients() = json2Patients(j)
if response.len =0 then exit
for w=0 to patients.Ubound
msgbox patients(w).id
msgbox patients(w).surname
msgbox patients(w).name
msgbox patients(w).sex
msgbox patients(w).birthdate
next
what do I need to modify to read the first string. The code shown isn’t entirely my own work
but rather your previous help.