赞
踩
使用 jobject
JObject jsonObj = JsonConvert.DeserializeObject(retString) as JObject;
获取对应值:
int intni = jsonObj.Value(“Code”);
mvc转换json 返回值为JsonResult
实体转json
string strJson = JsonConvert.SerializeObject(maxList);
json转实体
maxList = JsonConvert.DeserializeObject<List<List<MainInfoMx>>>(ReadAll);
其他转换格式:
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);
}
}
}
}
}
有时候 使用
JObject JBOnePeson = new JObject(item.ToString());
会提示错误
推荐使用 JObject JBOnePeson = JObject.Parse(item.ToString());
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。