Android Question can't parse this json data

Discussion in 'Android Questions' started by ykucuk, Apr 5, 2015.

  1. ykucuk

    ykucuk Active Member Licensed 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
    }
    ]
     
  2. NJDude

    NJDude Expert Licensed User

    Try this code:
    Code:
    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")
     
    thedesolatesoul likes this.
  3. ykucuk

    ykucuk Active Member Licensed 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
     
  4. NJDude

    NJDude Expert Licensed User

    Then use this code:
    Code:
    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
     
    thedesolatesoul likes this.
  5. NJDude

    NJDude Expert Licensed User

    You can use THIS code to help you parse JSON as well.
     
    thedesolatesoul likes this.
  6. ykucuk

    ykucuk Active Member Licensed 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
     
  7. NJDude

    NJDude Expert Licensed User

    Check the JSON string, if it's the same you posted above you are missing a "[" in the beginning.
     
    thedesolatesoul likes this.
  8. ykucuk

    ykucuk Active Member Licensed User

    thank you for great help.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice