I have a json string that I would like to iterate through to retrieve a specific value. In this object, there are multiple items, each with the same elements. What i am trying to do is search through each item for its request_item.u_requested_for.user_name, and compare it to a different value. If it does NOT match, move on. If it does match, then i want to retrieve the request_item.u_requested_for.sys_id value. Additionally, the size of the json will not always be the same. Sometimes there will be 5 elements, other times 20. How can I loop through each item, do the comparison, and then retrieve the other value that I need?
I've played around with this using other ideas I've found, but I'm unable to really get it working. First, should i parse the string into an object using JObject.Parse()? Or should I continue working with this as as string?
I've tried using a JsonTextReader to read through each line, but I'm unsure how I would retrieve the value I need once I find the item that matches the criteria.
{
"result": [
{
"request_item.sys_id": "db6e3306dbc3ef8c791a777a8c961986",
"request_item.u_requested_for.sys_id": "8416ccb3dba9df8c1ddee3a84b961911",
"request_item.u_requested_for.user_name": "H298956"
},
{
"request_item.sys_id": "e5990f89db47ebc8bd663ebd7c96198f",
"request_item.u_requested_for.sys_id": "878ce1d5dbcd0300cc78dd0b5e961987",
"request_item.u_requested_for.user_name": "E092733"
},
{
"request_item.sys_id": "87970c08db4be388791a777a8c9619ee",
"request_item.u_requested_for.sys_id": "484a1cf5db5f83c04f6489584b961952",
"request_item.u_requested_for.user_name": "H281111"
}
]
}
In this case, I want to iterate through each item and look for the value "H281111". Once I find that value, I want to extract the "request_item.u_requested_for.sys_id value", which in this case is "484a1cf5db5f83c04f6489584b961952".