Android Question can't parse this json data

ykucuk

Well-Known Member
Licensed User
Longtime User
Hello,

i did read a lot of tutorials but i can parse only 1.st item no luck with other items.

any help ?


{
"ButtonID": 2,
"Title": "Kampanyalar",
"Description": "Otomobil Satış Sonrası Hizmetleri",
"Link": "",
"Target": "Internal",
"UserID": 8040,
"Row": 0
},
{
"ButtonID": 13,
"Title": "Filmler",
"Description": "Tutkuların Dünyası",
"Link": "",
"Target": "Internal",
"UserID": 8040,
"Row": 1
},
{
"ButtonID": 19,
"Title": "Collection Konfigüratör",
"Description": "Collection Konfigüratör",
"Link": "http://www.mercedes-benz.com.tr/con...c_Aksesuarlar_/collection_new/collection.html",
"Target": "External",
"UserID": 8040,
"Row": 2
},
{
"ButtonID": 20,
"Title": "MB Sport",
"Description": "MB Sport",
"Link": "http://sport.mercedes-benz.com/index-tr.html",
"Target": "External",
"UserID": 8040,
"Row": 3
},
{
"ButtonID": 28,
"Title": "MB INT",
"Description": "test",
"Link": "http://www.mercedes-benz.com",
"Target": "External",
"UserID": 8040,
"Row": 4
},
{
"ButtonID": 29,
"Title": "Yedek Parça",
"Description": "test 123",
"Link": "",
"Target": "Internal",
"UserID": 8040,
"Row": 5
},
{
"ButtonID": 30,
"Title": "Test",
"Description": "aaaaa",
"Link": "http://www.mbusa.com",
"Target": "External",
"UserID": 8040,
"Row": 6
}
]
 

NJDude

Expert
Licensed User
Longtime User
Try this code:
B4X:
Private jParser As JSONParser

jParser.Initialize(JSONText)

Private Root As Map = jParser.NextObject
Private ButtonID As Int = Root.Get("ButtonID")
Private Target As String = Root.Get("Target")
Private Description As String = Root.Get("Description")
Private UserID As Int = Root.Get("UserID")
Private Title As String = Root.Get("Title")
Private Row As Int = Root.Get("Row")
Private Link As String = Root.Get("Link")
 
Upvote 0

ykucuk

Well-Known Member
Licensed User
Longtime User
Thank you NjDude. I try but it parse only 1st row. how can i parse all rows. i am very beginner of json format. could you help me if you can
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Then use this code:
B4X:
Private jParser As JSONParser

jParser.Initialize(JSONText)

Private Root As List = jParser.NextArray


For Each ColRoot As Map In Root

    Private ButtonID As Int = ColRoot.Get("ButtonID")
    Private Target As String = ColRoot.Get("Target")
    Private Description As String = ColRoot.Get("Description")
    Private UserID As Int = ColRoot.Get("UserID")
    Private Title As String = ColRoot.Get("Title")
    Private Row As Int = ColRoot.Get("Row")
    Private Link As String = ColRoot.Get("Link")
   
Next
 
Upvote 0

ykucuk

Well-Known Member
Licensed User
Longtime User
Thank you for help but still error.

java.lang.RuntimeException: JSON Array expected.

Private jParser As JSONParser
jParser.Initialize(File.ReadString(File.DirAssets, "buttons.json"))
Private Root As List = jParser.NextArray ' There is error on this line
 
Upvote 0
Top