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 SetiaRank #308 · 8.2K reputationPosted May 17, 2021, 12:03 PM EDT
Sachin SinghRank #66 · 26.2K reputationPosted May 17, 2021, 3:11 PM EDT
Varun SetiaRank #308 · 8.2K reputationPosted May 17, 2021, 11:14 AM EDT
Sujeet RamanRank #1,329 · 1.3K reputationPosted May 17, 2021, 11:21 AM EDT
Varun SetiaRank #308 · 8.2K reputationPosted May 17, 2021, 11:29 AM EDT
You can use them like this in logic.
Except, i cannot find use of nextPageToken, but you can keep that.
Sujeet RamanRank #1,329 · 1.3K reputationPosted May 17, 2021, 11:34 AM EDT
Sujeet RamanRank #1,329 · 1.3K reputationPosted May 17, 2021, 11:50 AM EDT
Sujeet RamanRank #1,329 · 1.3K reputationPosted May 18, 2021, 2:37 AM EDT
Varun SetiaRank #308 · 8.2K reputationPosted May 17, 2021, 10:49 AM EDT
Sujeet RamanRank #1,329 · 1.3K reputationPosted May 17, 2021, 11:11 AM EDT