Although that is valid json the values would all have quotes around them inside the quotes for json
instead of value =
/neda/live-post-image/1.jpg
it would actually be
"/neda/live-post-image/1.jpg" as the value so you may need to remove the extraneous quotes
Log("----- Create Json -----")
Dim LinkList1 As List
LinkList1.Initialize
LinkList1.Add("/neda/live-post-image/1.jpg")
LinkList1.Add("/neda/live-post-image/2.jpg")
LinkList1.Add("/neda/live-post-image/3.jpg")
Dim m As Map = CreateMap("repeated_string": CreateMap("value":LinkList1))
Dim sJson As String = m.As(JSON).ToString
Log(sJson)
Log("----- Add more lists -----")
Dim MapJson As Map = sJson.As(JSON).ToMap
MapJson.Get("repeated_string").As(Map).Get("value").As(List).Add("/neda/live-post-image/4.jpg")
MapJson.Get("repeated_string").As(Map).Get("value").As(List).Add("/neda/live-post-image/5.jpg")
MapJson.Get("repeated_string").As(Map).Get("value").As(List).Add("/neda/live-post-image/6.jpg")
Dim sJson As String = MapJson.As(JSON).ToString
Log(sJson)
Log("----- Read Json -----")
Dim repeated_string As Map = sJson.As(JSON).ToMap.Get("repeated_string")
Dim value As List = repeated_string.Get("value")
For Each Link As String In value
Log(Link)
Next
Dim s As String=$"
{"repeated_string":{
"value":[
"\"\/neda\/live-post-image\/1.jpg\"",
"\"\/neda\/live-post-image\/2.jpg\"",
"\"\/neda\/live-post-image\/3.jpg\""
]
}}"$
Log( Regex.Replace("\\",Regex.Replace($"\\""$, s, ""),""))
Thank you for answering my question.
Do we always need to use the Replace method? What if there is a backslash in the string—will the result still apply to our string!
Private LinkList As List
LinkList.Initialize
LinkList.Add("/neda/live-post-image/1.jpg")
LinkList.Add("/neda/live-post-image/2.jpg")
LinkList.Add("/neda/live-post-image/3.jpg")
Dim JsonText As String =$"{"repeated_string":{}}"$
Private parser As JSONParser
parser.Initialize(JsonText)
Private jRoot As Map = parser.NextObject
Private Images_repeated_string As Map = jRoot.Get("repeated_string")
Images_repeated_string.Put("value",LinkList)
jRoot.Put("repeated_string",Images_repeated_string)
Dim newjsontext As String
Private JSONGenerator1 As JSONGenerator
JSONGenerator1.Initialize(jRoot)
newjsontext = JSONGenerator1.ToString.Replace("\/","/")
Log(newjsontext)