Hi, I am trying to parse the return from http://www.recipepuppy.com/api/?i=onions,garlic&q=omelet&p=3 into a listview using Json. (Its for a lesson). I have attacked it from a number of angles for a few hours and had no luck. I know its easy, but can someone have a look at it for me please?
I saved the file as a text file just to get it working.
I saved the file as a text file just to get it working.
B4X:
'parse the json file
Activity.LoadLayout("main")
Dim JSON As JSONParser
Dim Map1 As Map
If File.Exists(File.DirAssets, "recipie.txt")Then
JSON.Initialize(File.ReadString(File.DirAssets, "recipie.txt"))
Map1 = JSON.NextObject
Dim m As Map 'helper map for navigating
Dim ingredients As List 'list holds all the recipies
ingredients.Initialize
m = Map1.Get("results")'top level with a key: the value is everything else in the code. key:value pass it to m
'm = m.Get("title")
ingredients = m.Get("results")' get out the ingredients
For i = 0 To ingredients.Size - 1
m = ingredients.Get(i)
Log(m.Get("title"))
lvrecipie.AddSingleLine("title" & " " & "ingredients")
Next
Else
ToastMessageShow("no file", "")
End If