先把json转成实体,这里帮你把实体类写好了
public class Rootobject
{
public Root[] Root { get; set; }
}
public class Root
{
public string datetime { get; set; }
public string measparam { get; set; }
public string value { get; set; }
public string unit { get; set; }
public string type { get; set; }
public string dataflag { get; set; }
}
之后你需要写一个json反序列化函数,这个需要引用System.Web.Extensions
public static T BeginJsonDeserialize<T>(string str)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Deserialize<T>(str);
}
然后把你的json语句反序列化成对象
var json = BeginJsonDeserialize<Rootobject>("[{\"datetime\":\"2019/9/2 13:46:00\",\"measparam\":\"w01018\",\"value\":411.839996337891,\"unit\":\"mg/L\",\"type\":1,\"dataflag\":\"N\"},{\"datetime\":\"2019/9/2 13:46:00\",\"measparam\":\"w21011\",\"value\":3.07800006866455,\"unit\":\"mg/L\",\"type\":1,\"dataflag\":\"N\"}]");
然后你就可以对这个实体做任何判断了,用linq会比较方便
例如
var m1 = json.Root.ToList().Find(p => p.measparam == "w01018");
var m2 = json.Root.ToList().Find(p => p.measparam == "w21011");
if(m1==null || m1.value!= "411.839996")
MessageBox.Show("w01018判断失败");
if (m2 == null || m2.value != "3.07800006866455")
MessageBox.Show("w21011判断失败");
全部代码截图
有用望采纳