TheSwamp
Code Red => .NET => Topic started by: FELIX on April 22, 2021, 11:50:12 PM
-
Dim JSLISTA = JsonConvert.DeserializeObject(JSON)
For Each LL As String In JSLISTA
'LL = {"id":9,"nserie0":"X9999","uname":"XXXXXX","cname":"YYYYYYY"}
'ERROR = Conversion of type 'JObject' to type 'String' is not valid
MsgBox(LL("id") & " - " & LL("nserie0") & " - " & LL("uname") & " - " & LL("cname")) '<<<<<<<<<<
Next
-
Dim JSLISTA = JsonConvert.DeserializeObject(JSON)
For Each LL As String In JSLISTA
'LL = {"id":9,"nserie0":"X9999","uname":"XXXXXX","cname":"YYYYYYY"}
'ERROR = Conversion of type 'JObject' to type 'String' is not valid
MsgBox(LL("id") & " - " & LL("nserie0") & " - " & LL("uname") & " - " & LL("cname")) '<<<<<<<<<<
Next
You need define a Type/Class that matches the JSON data structure: something like (sorry, code in C#):
public class MyObject
{
public int id { set; get; }
public string nserie0 { set; get; }
public string uname { set; get; }
public string cname { set; get; }
}
when deserializing JSON string, you do
var jsList = JsonConvert.DeserializeObject<MyObject>(jsonString);
foreach (var item in jsList)
{
MessageBox.Show($"id: {item.id} - nserie0: {item.nserie0} - uname: {item.uname} - cname: {item.cname}");
}
-
n.yuan your code didn't work because JSLISTA is a JSON ARRAY but from your code I managed to solve it.
Thank you so much.
Dim JSLISTA = JsonConvert.DeserializeObject(JSON) 'JSON / JSLISTA >>> ARRAY <<<
For Each JSL As Linq.JObject In JSLISTA
MessageBox.Show($"id: {JSL.Item("id")} - nserie0: {JSL.Item("nserie0")} - uname: {JSL.Item("uname")} - cname: {JSL.Item("cname")}")
Next