Abdull Cadre Active Member Licensed User Longtime User Jul 26, 2022 #1 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: Copy "requestedBy": "{\"id\":468,\"email\":\"[email protected]\",\"name\":\"Abdul Cadre\"}" but I can't. I can already do something like this⬇⬇⬇ without any problem: JSON: Copy "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
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: Copy "requestedBy": "{\"id\":468,\"email\":\"[email protected]\",\"name\":\"Abdul Cadre\"}" but I can't. I can already do something like this⬇⬇⬇ without any problem: JSON: Copy "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 Erel Jul 26, 2022 Code: Copy Dim userJson As Map = CreateMap("email": "[email protected]","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)
Code: Copy Dim userJson As Map = CreateMap("email": "[email protected]","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)
S Spavlyuk Active Member Licensed User Longtime User Jul 26, 2022 #2 Take a look here: https://www.b4x.com/android/help/json.html Upvote 0
Abdull Cadre Active Member Licensed User Longtime User Jul 26, 2022 #3 Solved: B4X: Copy Dim userJson As Map = CreateMap("email": "[email protected]","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: Copy {"requestedBy":"{\"email\":\"[email protected]\",\"id\":750,\"name\":\"Abdul Cadre\"}"} Thanks Upvote 0
Solved: B4X: Copy Dim userJson As Map = CreateMap("email": "[email protected]","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: Copy {"requestedBy":"{\"email\":\"[email protected]\",\"id\":750,\"name\":\"Abdul Cadre\"}"} Thanks
Erel B4X founder Staff member Licensed User Longtime User Jul 26, 2022 #4 Code: Copy Dim userJson As Map = CreateMap("email": "[email protected]","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) Upvote 1 Solution
Code: Copy Dim userJson As Map = CreateMap("email": "[email protected]","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)