Finding a node (JObject) within JArray using JSON.NET library

前端 未结 1 456
感动是毒
感动是毒 2020-12-10 15:16

I am using JSON.NET library. I have created few JObjects and added them to a JArray.

JArray array = new JArray();

JObject obj = new JObject();
obj.Add(new J         


        
相关标签:
1条回答
  • 2020-12-10 15:53

    You can find it like this:

    JObject jo = array.Children<JObject>()
        .FirstOrDefault(o => o["text"] != null && o["text"].ToString() == "Two");
    

    This will find the first JObject in the JArray having a property named text with a value of Two. If no such JObject exists, then jo will be null.

    0 讨论(0)
提交回复
热议问题