C# String Dictionary Json Jobject等数据相互转换。

Dictionary JObject  转 String

string  result  = JsonConvert.SerializeObject(dic);

String转JObject

string returnMsg = HttpPost(url, JsonConvert.SerializeObject(jo));
                        JObject ob = (JObject)JsonConvert.DeserializeObject(returnMsg);
                        if (Convert.ToBoolean(ob["Type"]))
                        {
                            //xxxxx
                        }
                        else
                        {
                          //xxxx
                        }

string转 JArray

string registerJson= HttpPost(url, JsonConvert.SerializeObject(jo));

JArray jo = (JArray)JsonConvert.DeserializeObject(registerJson);
                                        foreach (var ss in jo)  //查找某个字段与值
                                        {
                                            string inoc_bact_code = ss["inoc_bact_code"].ToString();

                                        }

 

你可能感兴趣的:(c#)