Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4android > Basic4android Updates and Questions
Documentation Wiki Register Members List Windows Mobile Search Today's Posts Mark Forums Read

Basic4android Updates and Questions Updates and questions regarding Basic4android.

Json parsing problems

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-17-2010, 09:38 AM
Basic4android Expert
 
Join Date: Sep 2007
Posts: 688
Default Json parsing problems

I must be totallt stupid but below json does not work for me to parse:

{
"code": 200,
"data": {
"items": [
{
"title": "test 0"
},
{
"title": "test 1"
}
]
}
}

I use the following code to do this:

Dim JSON As JSONParser
Dim jsonMap As Map
Dim jsonResultMap As Map 'helper map for navigating
Dim jsonItems As List

'initialize json
JSON.Initialize(File.ReadString(File.DirAssets, "example1.json"))

'get objects
jsonMap = JSON.NextObject

'get data object for non array items
jsonResultMap=jsonMap.Get("data")
'move to next object from data structure

'or use a list for arrays
'jsonResultMap=jsonResultMap.Get("data")
jsonItems = jsonResultMap.Get("items")
For i = 0 To jsonItems.Size - 1
jsonItems = jsonItems.Get(i)
Log(jsonItems.Get("title"))
Next
Reply With Quote
  #2 (permalink)  
Old 12-17-2010, 10:37 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 25,807
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Code:
{
    
"code"200,
    
"data"
    {
        
"items"
        [
            {
            
"title""test 0"
            },
            {
            
"title""test 1"
            }
        ]
    }
}
The "items" array contains two objects (each with a single "title" value).
You should change this:
Code:
For i = 0 To jsonItems.Size - 1
        jsonItems = jsonItems.Get(i) 
'<----------
        Log(jsonItems.Get("title"))
    
Next
To:
Code:
For i = 0 To jsonItems.Size - 1
        jsonresultMap = jsonItems.Get(i)
        
Log(jsonResultMap.Get("title"))
    
Next
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
XML Parsing with the XmlSax library Erel Basic4android Getting started & Tutorials 88 05-17-2013 04:05 PM
Android JSON tutorial Erel Basic4android Getting started & Tutorials 33 05-07-2013 02:08 PM
New JSON library - v1.00 Erel Additional libraries, classes and official updates 0 12-16-2010 09:54 AM
GPS.dll parsing keywords epo Questions (Windows Mobile) 3 11-11-2009 12:46 PM
File Parsing Smee Questions (Windows Mobile) 3 05-28-2009 04:18 PM


All times are GMT. The time now is 02:48 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0