I have a problem when send json string with patchstring the problem is that json.Put("Videos",CreateMap(videoname:videoUrl)) replace old string i need to append it not replace
my code is
json2:
Dim json As Map
json.Initialize
json.Put("Active",Active)
json.Put("ID",ID)
json.Put("UserName",UserName)
json.Put("Country",Country1)
json.Put("Img",Img)
json.Put("Email",Email1)
If videoUrl ="" Then
Else
json.Put("Videos",CreateMap(videoname:videoUrl)) 'probleme hier it replace old string
' my json is :
' Active :"ON"
' Country :""
' Email:"myemail"
' ID:"myid"
' Img:"imglink"
' UserName:"myname"
' Videos
' videos253998 :"videoslink" ' it replace this string hier
End If
Dim jgen As JSONGenerator
jgen.Initialize(json)
Log(jgen.ToPrettyString(2))
Dim j As HttpJob : j.Initialize("",Me)
j.PatchString(Urlpath,jgen.ToString)
I have a problem when send json string with patchstring the problem is that json.Put("Videos",CreateMap(videoname:videoUrl)) replace old string i need to append it not replace
json.Put("Videos",CreateMap(videoname:videoUrl)), it overwrites the previous item with the key Videos.
CreateMap(videoname:videoUrl) just creates a new map not append.
if you want to append a new item in key videos, you need to get old items from old videos map and put them and a new item into a new map, such as json.put("videos", thenewmap) or json.put("videos", createmap(oldkeysldurls, ... videoname:videoUrl).
Dim parser As JSONParser
parser.Initialize(<text>)
Dim jRoot As Map = parser.NextObject
Dim Active As Int = jRoot.Get("Active")
Dim Img As Int = jRoot.Get("Img")
Dim UserName As Int = jRoot.Get("UserName")
Dim Email As Int = jRoot.Get("Email")
Dim Country As Int = jRoot.Get("Country")
Dim videos As List = jRoot.Get("videos")
For Each colvideos As Map In videos
Dim videoname As String = colvideos.Get("videoname")
Next
Dim ID As Int = jRoot.Get("ID")
Do you own the web service?
What is the documentation says?
Sometimes we send a :
POST - normally use to create a new record or override existing
PUT - normally use to update or override existing record
It is better refer to the documentation or if you are the one develop it then you need to determine how it handles the incoming json data.
Edit: I read again the first post and noticed that you mentioned about PATCH string. I never work with PATCH method and not very sure how the internal works. If I am not mistaken, when we PATCH, we only supply a partial of fields that need to be updated instead of mixture of non to-be-updated and to-be-updated fields.
First of all, some definitions: PUT is defined in Section 9.6 RFC 2616: The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an a...
Hi I need to parse this json with two way one with json parser and one for regex parse Active Country Email ID Img UserName videos1 and videos2 and videos3 .................. the id is random string { "Users": { "RCYzpiJLRkcUfaPi7Pxu1OxGFTi2": { "Active": "ON", "Country"...
from what I see in your Json structure.
I wonder the following:
Do element keys have fixed names?
How many elements does the video group have?
Are group names duplicated?
{
"uxkbwCtt7bZnsxcRtqw2QRHmmw32": { ---> Can the name be duplicated?
"Active": "ON",
"Country": "mycountry",
"Email": "myemail",
"ID": "uxkbwCtt7bZnsxcRtqw2QRHmmw32",
"Img": "https://..png",
"UserName": "myname",
"Videos": { ---> Group
"videos1215021": "https..mp4" ---> elements 1 to n?? and Can the name be duplicated?
}
}
}
Thank's for replay
Do element keys have fixed names?
Yes, all except for the video125 it is a random variable
How many elements does the video group have?
not fixed I use a video random value as key like this videos1524 for not replace it when send it with patchstring ,because want to append more videos
I have a problem when send json string with patchstring the problem is that json.Put("Videos",CreateMap(videoname:videoUrl)) replace old string i need to append it not replace
As a non-native English speaker, I wonder whether this recognizable somewhat unfortunate spelling means that the questioner actually means that he wants to add a url every time. If the questioner wants it, the json file is designed wrong. It should not work with a fix url field for each url, but with only one fix url field in a json array. Then you can add "endless" urls or you have to choose a fixed number of possible urls.
Most importantly, the statement "replace old string" says absolutely nothing about what should be done in which situation. It's all about When and How do you do What? Or elaborated: when do you do nothing (url = equal), when and how do you add (fix fields count or unlimited fields)?
Personally I think you need the following JSON file design:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim jRoot As Map = parser.NextObject
Dim users As Map = jRoot.Get("users")
Dim user As List = users.Get("user")
For Each coluser As Map In user
Dim Active As String = coluser.Get("Active")
Dim UserName: As String = coluser.Get("UserName:")
Dim Email: As String = coluser.Get("Email:")
Dim Img As String = coluser.Get("Img")
Dim Country As String = coluser.Get("Country")
Dim ID As String = coluser.Get("ID")
Dim Videos As List = coluser.Get("Videos")
For Each colVideos As Map In Videos
Dim videoname As String = colVideos.Get("videoname")
Next
Next