Android Question stringify

Abdull Cadre

Active Member
Licensed User
Good morning everyone, hope you are well.
I hope this thread is not repeated, I looked for the solution on the forum but I didn't find it, maybe it's my weak English.
is the following: I'm trying to generate a json string like this ⬇⬇⬇⬇:
JSON:
"requestedBy": "{\"id\":468,\"email\":\"abdul.cadre@moz.com\",\"name\":\"Abdul Cadre\"}"
but I can't.
I can already do something like this⬇⬇⬇ without any problem:
JSON:
"details":  [
           {
            "accountId": "null",
            "departament": "null",
            "description": "Luna del marta",
            "price": 123,
            "product": 2486,
            "total": 123,
            "vat": 12,
            "vehicle": "null"
          }
        ]

if anyone has gone through this please help
 
Solution
B4X:
Dim userJson As Map = CreateMap("email": "exemplo@mail.com","id":750,"name": "Abdul Cadre")
Dim dataPrintP As Map = CreateMap("requestedBy": userJson.As(JSON).ToCompactString)
Dim s As String = dataPrintP.As(JSON).ToCompactString
Log(s)

Abdull Cadre

Active Member
Licensed User
Solved:

B4X:
Dim userJson As Map = CreateMap("email": "exemplo@mail.com","id":750,"name": "Abdul Cadre")
Dim jg As JSONGenerator
jg.Initialize(userJson)
Dim dataPrintP As Map = CreateMap("requestedBy":jg.ToString)     
Dim jg As JSONGenerator
jg.Initialize(dataPrintP)
Log(jg.ToString)

output:
JSON:
{"requestedBy":"{\"email\":\"exemplo@mail.com\",\"id\":750,\"name\":\"Abdul Cadre\"}"}

Thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…