Android Question JSON if empty field ... ?

Discussion in 'Android Questions' started by pierrem, Feb 1, 2015.

  1. pierrem

    pierrem Member Licensed User


    While processing json string ...

    {'id':'4','name':'my beautifull launderette','business_type':'1','param':{'phone':'+332222222','fax':'x'}}
    is parsed perfectly ...

    but if field 'fax' is empty, like :
    {'id':'4','name':'my beautifull launderette','business_type':'1','param':{'phone':'+332222222','fax':''}}
    then I got an error

    How to workaround ?

    (full code in the zip file)

    Thanks in advance

    Attached Files:

  2. eurojam

    eurojam Well-Known Member Licensed User

    I think there was an error in your json parser routine. I always use the B4J Json tree example to parse my json strings correctly ( Parsing your string with this it works with an empty fax:
    Dim s As String ="{'id':'4','name':'my beautifull launderette','business_type':'1','param':{'phone':'+332222222','fax':''}}"
    Dim parser As JSONParser
    Dim root As Map = parser.NextObject
    Dim id As String = root.Get("id")
    Dim param As Map = root.Get("param")
    Dim phone As String = param.Get("phone")
    Dim fax As String = param.Get("fax")
    Dim name As String = root.Get("name")
    Dim business_type As String = root.Get("business_type")
    Log("Fax: " & fax)
  3. pierrem

    pierrem Member Licensed User

    only one word : thks !
    eurojam likes this.
  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