My problem is as follows:
I have a Public sub created which looks like this for the moment:
Public Sub eniroContacts()
Dim phone As String = newCustPhone1.text
Dim url As String = "http://bedrift.telefonkatalogen.no/tk/search.php?qry=" + phone + "&from=1&to=27&format=json&username=user&password=pw"
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
Dim reader As StreamReader = New StreamReader(response.GetResponseStream())
Dim o As JObject = JObject.Parse(reader.ReadToEnd)
lblMsg.Text = o.ToString
reader.Close()
response.Close()
End Sub
so far so good and my lblMsg.Text displays the json string i want to get my data from (formatted for clarity):
{
"qry": "92020945",
"result": {
"hitLinesBeforeFilter": 1,
"userID": 299228,
"1": {
"listing": {
"table": "listing",
"id": "3647950",
"duplicates": [{
"table": "listing",
"id": "3647950:0",
"idlinje": "E19CMOD",
"tlfnr": "99887766",
"etternavn": "Omnes",
"fornavn": "Martin",
"veinavn": "Highway",
"husnr": "20",
"postnr": "0601",
"virkkode": "P",
"apparattype": "M",
"telco": "TM",
"kilde": "E",
"bkdata": "M",
"prioritet": "0",
"fodselsdato": "1976-07-03",
"kommunenr": "301",
"poststed": "Oslo",
"kommune": "Oslo",
"fylke": "Oslo",
"landsdel": "Ø"
}]
}
},
"dummy": null
}
}
What I want to do now is to actually fetch some of the values in the string and put them into some of my textboxes and labels, but don't have a clue on how can I do that. For example, I would want the values "fornavn", "tlfnr" and "fylke". The values are Martin, 99887766 and Oslo in this example, which should be put in textbox1, 2 and 3.
Also i would like to add that some of the Fields may not be there on some searched, like the first name ("fornavn" in my example). When this isnt there and i try writing:
Dim fornavn = o("result")("1")("listing")("duplicates")(0)("fornavn")
it crashes. Something i can do to prevent this in these scenarios?
Any clues and tips are very appreciated! :)