Hi
I have a function which will check given project name is include in the json object. For that I am not getting a proper json object in my response how to do that?
this is my object
{"projects":[{"name":"projects/sTest"},{"name":"projects/A345"},{"name":"projects/off"},{"name":"projects/dds"}]
i have one main method which will call public bool CheckDuplicate(string name) method to return whether any same name inside the object or not.
- public async Task<string> UploadData(string name, string url)
- {
- var hasMatch = CheckDuplicate(name);
- //post project_name methode here which will happen only hasmatch is false.need to block same names
- }
- public bool CheckDuplicate(string name)
- {
- string pname = name.Substring(9, name.Length - 9);
- HttpClient client = new HttpClient();
- client.BaseAddress = new Uri(httpRequest);
- client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- HttpResponseMessage response = client.GetAsync(httpRequest).Result;
- var result = response.Content.ReadAsStringAsync().Result;
- in result i am getting my objects like
- {"projects":[{"name":"projects/sTest"},{"name":"projects/A345"},{"name":"projects/off"},{"name":"projects/dds"}]
- var JSONObj = JsonConvert.DeserializeObject(result);
- // i am getting values in JSONObj but below code is not working
- //cant check the given pname is there or not
- var hasMatch = false;
- for (var index = 0; index < JSONObj.length; ++index)
- {
- var Projects = JSONObj[index];
- if (Projects.name == pname)
- {
- hasMatch = true;
- }
- else
- {
- hasMatch = false;
- }
- }
- return hasMatch;
- }
Varun SetiaPosted May 17, 2021, 4:03 PM
Sujeet RamanPosted May 18, 2021, 6:37 AM
Sachin SinghPosted May 17, 2021, 7:11 PM
Sujeet RamanPosted May 17, 2021, 3:50 PM
Sujeet RamanPosted May 17, 2021, 3:34 PM
Varun SetiaPosted May 17, 2021, 3:29 PM
You can use them like this in logic.
Except, i cannot find use of nextPageToken, but you can keep that.
Sujeet RamanPosted May 17, 2021, 3:21 PM
Varun SetiaPosted May 17, 2021, 3:14 PM
Sujeet RamanPosted May 17, 2021, 3:11 PM
Varun SetiaPosted May 17, 2021, 2:49 PM