Just getting started with XOJO, and I’m having trouble figuring out how to parse some JSON data. Any help would be appreciated.
JSON:
[
{
"id": 530,
"type": "Asset",
"assetNumber": "W-D-7154",
"macAddress": "00:00:00:00:00:00",
"networkName": "W-D-7154",
"model": {
"id": 340,
"type": "Model",
"modelName": "Compaq dc7800 ",
"manufacturer": {
"id": 16,
"type": "Manufacturer"
}
}
},
{
"id": 2605,
"type": "Asset",
"assetNumber": "W-L-007",
"macAddress": "00:00:00:00:00:00",
"networkName": "W-L-007",
"model": {
"id": 519,
"type": "Model",
"modelName": "Surface Book",
"manufacturer": {
"id": 48,
"type": "Manufacturer"
}
}
},
{
"id": 734,
"type": "Asset",
"assetNumber": "W-L-7003",
"macAddress": "00:00:00:00:00:00",
"networkName": "W-L-7003",
"model": {
"id": 5,
"type": "Model",
"modelName": "TECRA A11",
"manufacturer": {
"id": 5,
"type": "Manufacturer"
}
}
},
{
"id": 1677,
"type": "Asset",
"assetNumber": "W-L-7102",
"macAddress": "00:00:00:00:00:00",
"networkName": "W-L-7102",
"model": {
"id": 5,
"type": "Model",
"modelName": "TECRA A11",
"manufacturer": {
"id": 5,
"type": "Manufacturer"
}
}
},
{
"id": 620,
"type": "Asset",
"assetNumber": "W-L-9182",
"macAddress": "00:00:00:00:00:00",
"networkName": "W-L-9182",
"model": {
"id": 49,
"type": "Model",
"modelName": "OptiPlex 790",
"manufacturer": {
"id": 3,
"type": "Manufacturer"
}
}
}
]
Hacked together code modified from “JSON web feed app” example:
[code]If HTTPStatus = 200 Then
Dim jsonText As Text = Xojo.Core.TextEncoding.UTF8.ConvertDataToText(Content)
Dim jsonArray() As Auto = Xojo.Data.ParseJSON(jsonText)
For Each jsonDict As Xojo.Core.Dictionary In jsonArray
FeedList.DeleteAllRows
// Display the feed title
//FeedTitleLabel.Text = jsonDict.Value("title")
// Display the feed articles
Dim items() As Auto = jsonDict.Value(0)
For Each article As Xojo.Core.Dictionary In items
Dim id As Text = article.Value("id")
Dim assetNumber As Text = article.Value("assetNumber")
FeedList.AddRow(id, assetNumber)
// Save article content
//FeedList.RowTag(FeedList.LastIndex) = article.Value("content_html")
Next
Next
End If[/code]