Android Question Json parser issue

vincentehsu

Member
Licensed User
Longtime User
B4X:
{"Load_JobTitleResult":"[{\"EnterpriseID\":1,\"AttribName\":\"Test\",\"JobTitleID\":1,\"JobTitle\":\"Admin\"},{\"EnterpriseID\":1,\"AttribName\":\"Test\",\"JobTitleID\":8,\"JobTitle\":\"OP\"}]"}

I don't know how to parse the josn collection,is there any sample code to do this?
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As Map = parser.NextObject
Dim Load_JobTitleResult As String = root.Get("Load_JobTitleResult")

See http://basic4ppc.com:51042/json/index.html

Edit: Why are the deeper jsondata have slashes?
 
Upvote 0

vincentehsu

Member
Licensed User
Longtime User
I don;t konw why,The services is built by .net.
B4X:
Dim parser As JSONParser
parser.Initialize(Job.GetString)
Dim root As Map = parser.NextObject
Dim Load_JobTitleResult As String = root.Get("Load_JobTitleResult")
                    Log(Load_JobTitleResult)

I just get []
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
- Replace the \ from the invalid json
- remove the wrong placed "

and then the parse can do the job.

This is how the json should look like:
{

"Load_JobTitleResult": [{"EnterpriseID":1,"AttribName":"美麗","JobTitleID":1,"JobTitle":"企業管理員"},{"EnterpriseID":1,"AttribName":"美麗","JobTitleID":8,"JobTitle":"機車"}]

}

And this - correct json - can be parsed like this
B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As Map = parser.NextObject
Dim Load_JobTitleResult As List = root.Get("Load_JobTitleResult")
For Each colLoad_JobTitleResult As Map In Load_JobTitleResult
Dim JobTitleID As Int = colLoad_JobTitleResult.Get("JobTitleID")
Dim AttribName As String = colLoad_JobTitleResult.Get("AttribName")
Dim JobTitle As String = colLoad_JobTitleResult.Get("JobTitle")
Dim EnterpriseID As Int = colLoad_JobTitleResult.Get("EnterpriseID")
Next

In fact the problems seems to be in the WCF web service!
 
Last edited:
Upvote 0
Top