B4J Question json string

codie01

Active Member
Licensed User
Longtime User
Hi All,

I am trying to convert the following into a json string.

{
"name": "DoogyDrink",
"description": "My Doggy Drink",
"visibility": "PRIVATE",
"variations": [
{
"name": "Small",
"pricing_type": "FIXED_PRICING",
"price_money": {
"currency_code": "NZD",
"amount": 400
},
"sku": "123"
}
]
}

Can anyone provide an example code,

Thanks for your help in advance.
Phil
 

codie01

Active Member
Licensed User
Longtime User
Thanks Guys,

From what I can see this extracts a json string, I want to do it in reverse, I want to know how to build the json string. Or am I looking at this wrong?

Thanks
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
I am trying to convert the following into a json string.
your text above was a JSON string but it is confusing because it contains ", the char " is just a byte with value 34

it used the lib Json
and a map to generate a json
B4X:
    Dim M As Map
    M.Initialize
    M.Clear
    M.Put("MyKey ABC","MyValue 123")

    Dim J As JSONGenerator
    J.Initialize(M)
    Dim Output As String = J.ToPrettyString(4)
    
    Log(Output)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…