Android Question JSON if empty field ... ?

pierrem

Member
Licensed User
Longtime User
Hi,

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
 

Attachments

  • test.zip
    6.3 KB · Views: 127

eurojam

Well-Known Member
Licensed User
Longtime 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 (http://www.b4x.com:51042/json/index.html). Parsing your string with this it works with an empty fax:
B4X:
Dim s As String ="{'id':'4','name':'my beautifull launderette','business_type':'1','param':{'phone':'+332222222','fax':''}}"
Dim parser As JSONParser
parser.Initialize(s)
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)
 
Upvote 0
Top