B4J Question Need help with JSON

G-ShadoW

Active Member
Licensed User
Longtime User
Hello, this is my first time that I use JSON Parser

here is link and I want to parse all results and show them in ListView.


B4X:
https://api.coingecko.com/api/v3/coins/markets?vs_currency=eur&ids=injective-protocol&order=market_cap_desc&per_page=1&page=1&sparkline=false&price_change_percentage=1h%2C24h%2C7d


B4X:
Sub Process_Globals
Private UrlPrices As String = "https://api.coingecko.com/api/v3/coins/markets?vs_currency=eur&ids=injective-protocol&order=market_cap_desc&per_page=1&page=1&sparkline=false&price_change_percentage=1h%2C24h%2C7d"
End Sub

Sub GetPrices As ResumableSub
    
    Dim jGF1 As HttpJob
    Dim ResJ As String
    
    jGF1.Initialize("GetInfo", Me)
    jGF1.Download(UrlPrices)
    
    Wait For (jGF1) JobDone(j As HttpJob)
    If j.Success Then
        ResJ = j.GetString
    Else
        Log(j.ErrorMessage)
        j.Release
        Return False
    End If
    j.Release
    
    Log(ResJ)
    ListView1.Items.Add(ResJ)
    'LoadPrices(ResJ)
    Return True

End Sub
Sub LoadPrices(ResJ As String)
    
    ...
    
End Sub
 

Mark Read

Well-Known Member
Licensed User
Longtime User
If I might suggest, have a look at my new post here and in particular the sub GetData on line 81 and the sub following that.

I used the same link Erel has suggested to get my info. The tool is great. This is your data and code.

1644759231107.png
 
Upvote 0

Hanz

Active Member
You can do something like this.

B4X:
Dim jp As JSONParser
    jp.Initialize(Json)
    
    Dim m As Map = jp.NextObject
    Dim rows As List = m.Get("rows")
    For Each row As Map In rows
        ...
    Next

JSON data is like this {...} . the content is presented as in key-value which is map in b4x. If the JSON contains [...] that means it is a list in b4x. So, get individual field by using map and list in b4x. After you get the data you can put them to listview or any other control.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I have one question, why never to use listview?
I would not myself use the words "never use Listview", but it is very limited in the functions that it provides and if you plan to do very much development in B4X then you would do better to invest your time becoming acquainted with more flexible and capable views. You are certainly going to need them one day.

Other people might have better answers.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
why never to use listview?
#1:

 
Upvote 0
Top