JSON to Array with LiveCode 8
Posted: Tue Jun 20, 2017 2:31 pm
Hi there,
I try to access information via a web API. The API provides the data in JSON format. It likes like this:
So I put a "Tree View" widget and a button on my card. The On MoseUp code of the Button looks like this:
This works fine and the data from the JSON API is put into the Tree View field. But I want only some specific Information put into th Tree View. So I have to "filter" the array in LiveCode but I have no idea how to get this working. I only want the following data:
From the "field" feed I like only the type BOSSKILL with all the corresponding data below. So if I look at the JSON file posted above I only want this data:
Do anybody have an idea how to get to this data in the array?
Thanks for your help
Benny
I try to access information via a web API. The API provides the data in JSON format. It likes like this:
Code: Select all
{
"lastModified": 1497254226000,
"name": "Sasinchen",
"realm": "Zirkel des Cenarius",
"battlegroup": "Embuscade / Hinterhalt",
"class": 11,
"race": 4,
"gender": 1,
"level": 110,
"achievementPoints": 13275,
"thumbnail": "zirkel-des-cenarius/199/102431431-avatar.jpg",
"calcClass": "U",
"faction": 0,
"feed": [{
"type": "CRITERIA",
"timestamp": 1497208249000,
"achievement": {
"id": 7447,
"title": "Mehr Spaß mit Freunden",
"points": 10,
"description": "Schließt 100 Szenarien in Gildengruppen ab.",
"rewardItems": [],
"icon": "achievement_scenariochallenge_100",
"criteria": [{
"id": 21188,
"description": "",
"orderIndex": 0,
"max": 100
}],
"accountWide": false,
"factionId": 2
},
"featOfStrength": false,
"criteria": {
"id": 21188,
"description": "",
"orderIndex": 0,
"max": 100
}
}, {
"type": "BOSSKILL",
"timestamp": 1497208249000,
"achievement": {
"id": 10883,
"title": "Siege über den Schemen von Xavius (Mythisch: Das Finsterherzdickicht)",
"points": 0,
"description": "",
"rewardItems": [],
"icon": "trade_engineering",
"criteria": [{
"id": 31384,
"description": "",
"orderIndex": 0,
"max": 1
}],
"accountWide": false,
"factionId": 2
},
"featOfStrength": false,
"criteria": {
"id": 31384,
"description": "",
"orderIndex": 0,
"max": 1
},
"quantity": 14,
"name": ""
}, {
"type": "LOOT",
"timestamp": 1497206270000,
"itemId": 138019,
"context": "",
"bonusLists": []
}, {
"type": "LOOT",
"timestamp": 1497206270000,
"itemId": 137513,
"context": "challenge-mode-2",
"bonusLists": [3414, 1532, 3528]
}, {
"type": "BOSSKILL",
"timestamp": 1497206262000,
"achievement": {
"id": 10898,
"title": "Siege über Cordana Teufelsang (Mythisch: Das Verlies der Wächterinnen)",
"points": 0,
"description": "",
"rewardItems": [],
"icon": "trade_engineering",
"criteria": [{
"id": 31415,
"description": "",
"orderIndex": 0,
"max": 1
}],
"accountWide": false,
"factionId": 2
},
...
Code: Select all
on mouseUp
local tBlizzardCharFeed
put url "https://eu.api.battle.net/wow/character/Zirkel%20des%20Cenarius/Sasinchen?fields=feed&locale=de_DE&apikey=5dxbkec7nrdju5tynks9dhg9kr86prrj" into tBlizzardCharFeed
if the result begins with "error" then
answer "Da stimmt was nicht"
else
answer "Das auslesen hat geklappt!"
put JSONToArray(tBlizzardCharFeed) into tBlizzardCharFeed
-- do something interesting with the profile
set the ArrayData of widget "Tree View" to tBlizzardCharFeed
end if
end mouseUp
From the "field" feed I like only the type BOSSKILL with all the corresponding data below. So if I look at the JSON file posted above I only want this data:
Code: Select all
{
"type": "BOSSKILL",
"timestamp": 1497206262000,
"achievement": {
"id": 10898,
"title": "Siege über Cordana Teufelsang (Mythisch: Das Verlies der Wächterinnen)",
"points": 0,
"description": "",
"rewardItems": [],
"icon": "trade_engineering",
"criteria": [{
"id": 31415,
"description": "",
"orderIndex": 0,
"max": 1
}],
"accountWide": false,
"factionId": 2
},
Thanks for your help
Benny