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);
-
- }
- 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);
-
-
- 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;
- }