当前位置:   article > 正文

解析返回的json文件(使用 jobject)_object obj= jsonconvert.deserializeobject

object obj= jsonconvert.deserializeobject

使用 jobject
JObject jsonObj = JsonConvert.DeserializeObject(retString) as JObject;
获取对应值:
int intni = jsonObj.Value(“Code”);

mvc转换json 返回值为JsonResult

实体转json

  string strJson = JsonConvert.SerializeObject(maxList);
  • 1

json转实体

 maxList = JsonConvert.DeserializeObject<List<List<MainInfoMx>>>(ReadAll);
  • 1

其他转换格式:

 string faceInfos = value["faces"].ToString();
                    JArray JFaceInfo =JArray.Parse(faceInfos);//string  转 JArray 
                    if (JFaceInfo!=null)
                    {
                        foreach (var item in JFaceInfo)
                        {
                            if (item!=null)
                            {
                                JObject JBOnePeson =  JObject.Parse(item.ToString());//string 转 JObject 注意这里用 new JObject 会出错
                                if (JBOnePeson!=null)
                                {
                                    ScanFaceLog model = new ScanFaceLog();
                                    try
                                    {
                                        model.image = JBOnePeson["image"]!= null ?JBOnePeson["image"].ToString() :string.Empty  ;
                                        model.camid = camid;
                                        model.devid = devid;
                                        model.InfosAll = string.Empty;//JBOnePeson.ToString();
                                        model.name = JBOnePeson["name"] != null ?  JBOnePeson["name"].ToString():string.Empty;
                                        model.personId = JBOnePeson["personId"] != null ?  JBOnePeson["personId"].ToString():string.Empty;
                                        model.gender = JBOnePeson["gender"] != null ?  JBOnePeson["gender"].ToString():string.Empty ;
                                        model.passType = JBOnePeson["passType"] != null ?int.Parse(JBOnePeson["passType"].ToString()) :2;
                                        ResultMsg msg = new DALScanFaceLog().Insert(model);
                                        if (msg.Success)
                                        {
                                            LogWrite.WriteLog("数据操作成功"); 
                                        }
                                        else
                                        {
                                            LogWrite.WriteLog("数据操作失败" + msg.ErrMsg);
                                        }
                                        
                                    }
                                    catch (Exception ex)
                                    {
                                        Msg.Code = 400;
                                        Msg.Msg= "失败的原因是:"+ex.Message;
                                        LogWrite.WriteLog(ex.Message);
                                    } 
                                }

                            }
                        }
                    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

有时候 使用
JObject JBOnePeson = new JObject(item.ToString()); 会提示错误

推荐使用 JObject JBOnePeson = JObject.Parse(item.ToString());

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号