update field in json

I want to update a particular field in json file through unitywebrequest. I have some Users ho logged in to their particular account updates their data in json. For updating data in json I am passing a token related to that user so that it can updated the particular field in json. My json is

“status”: “success”,
“data”: [
{
“id”: 1,
“user_id”: 2,
“name”: “Amitt Sharmaa 123”,
“date_of_birth”: “1997-09-21”,
“gender_title”: “Male”,
},
{
“id”: 2,
“user_id”: 1,
“name”: “chandresh”,
“date_of_birth”: “1989-06-28”,
“gender_title”: “Female”,
}]

Below is my code:

 WWWForm form = new WWWForm();
        form.AddField("name", "sam");
        form.AddField("date_of_birth", 1997-09-21);
        form.AddField("gender_title", "male");


        using (var w = UnityWebRequest.Post(url, form))
        {
            yield return w.SendWebRequest();
            if (w.isNetworkError || w.isHttpError)
            {
                print(w.error);
            }
            else
            {}
            }

So how can I update a field with a given particular token, I am generatint a token through jwt

Use JSONUtility, a [Serializable] class to model what you want to serialize, and do not use a WWWForm, use data. Also, that code has syntax errors.

Use Postman to test the request and use its "Code " function to convert the JSON request into c# code and pass the parameter for more.

1 Like