I'm manually building in code, some JSON files, but have a hit a problem where I need to ensure that characters like " ' [ & etc are encoded, as if I don't, the recipient can't parse the resulting file. Is there a function somewhere that will allow me to convert a text string to a JSON friendly string?
I'm manually building using the StringBuilder. Ideally I'll refactor to use the JSONGenerator, but short term, I just want to encode the text values, to ensure the JSON file can be parsed correctly at the other end.
I'm manually building in code, some JSON files, but have a hit a problem where I need to ensure that characters like " ' [ & etc are encoded, as if I don't, the recipient can't parse the resulting file. Is there a function somewhere that will allow me to convert a text string to a JSON friendly string?
If you build your own json string like you said what's the problem you are facing?
Characters " ' [ & should work just fine when json string is correctly created.
Just use \ with some characters like ' and \\ with the "
If you build your own json string like you said what's the problem you are facing?
Characters " ' [ & should work just fine when json string is correctly created.
Just use \ with some characters like ' and \\ with the "
If you find method you need from B4A libs like in this case lib JSON, it's very good chance that it is already made easy as it can be.
Like I pointed out my last message you need to take care of correct syntax with some special characters when dealing with json. JSON lib already takes care of this all automatically.
If you find method you need from B4A libs like in this case lib JSON, it's very good chance that it is already made easy as it can be.
Like I pointed out my last message you need to take care of correct syntax with some special characters when dealing with json. JSON lib already takes care of this all automatically.
Yes ideally I need to use the JSONGenerator, but I just want a quick fix now. This is what I ended up with.
B4X:
Sub StringToJSON(pText As String) As String
Dim lResult As String=""
Dim jgen As JSONGenerator
jgen.Initialize(CreateMap("Remove": pText))
lResult=Mid(jgen.ToString,12,jgen.ToString.Length-13)
Return lResult
End Sub