/// <summary>
/// 上行jsom格式日志记录
/// </summary>
/// <param name="responseJson"></param>
public static void WriteToMoJsomLog(string responseJson)
{
//{"error":"1","remark":"成功","statusbox":[{"mobile":"15510331875","taskid":"123","receivetime":"2015-01-01 00:00:00","errorcode":"dEv"},{"mobile":"13483728958","taskid":"124", "receivetime":"2015-02-01 00:00:00","errorcode":"back"}]}
//{"error":"1","remark":"成功","callbox":[{"mobile":"15510331875","taskid":"","content":"a","receivetime":"0001-01-01 00:00:00", "extno":"123" },{"mobile":"13483728958","taskid":"","content":"b","receivetime":"0001-01-01 00:00:00","extno":"456"}]}
try
{
MoObject obj = JsonDeserialize<MoObject>(responseJson);
string pathConfig = App.GetSetting("TracePath");
if (!string.IsNullOrWhiteSpace(pathConfig))
{
Log4NetTraceListener log = new Log4NetTraceListener(pathConfig + @"\UserInterface");
if (obj.Error == )
{
foreach (MoContent item in obj.Callbox)
{
log.WriteLine("获取上行成功:error :1"+",Remark:"+obj.Remark);
log.WriteLine("获取上行返回信息:" + "mobile:" +item.Mobile+ ",taskid:" + item.TaskId + ",content:" + item.Content + ",receivetime:" + item.ReceiveTime + ",extno:" +item.Extno ); }
}
else
{
log.WriteLine("获取上行Json格式返回错误:error:"+obj.Error+"Remark:"+obj.Remark);
}
}
}
catch (Exception ex)
{ throw new Exception("获取Json格式上行内容写入日志出错:" + ex);
}

未解析建的类型:

/// <summary>
/// 上行状态报告类型
/// </summary>
public class MoObject
{
public int Error { get; set; }
public string Remark { get; set; }
public MoContent[] Callbox { get; set; }
}
/// <summary>
/// 上行和状态报告内容类型
/// </summary>
public class MoContent
{
public string Mobile { get; set; }
public string TaskId { get; set; }
public string Content { get; set; }
public DateTime ReceiveTime { get; set; }
public string Extno { get; set; }
public string ErrorCode { get; set; }
}

解析方法:

 public static T JsonDeserialize<T>(string json) where T : class
{
if (string.IsNullOrWhiteSpace(json))
{
throw new ArgumentException("json");
}
return JsonConvert.DeserializeObject<T>(json);
}

Newtonsoft.Json解析Json字符串案例:的更多相关文章

  1. 【C#】使用Json.NET(newtonsoft)解析Json

    最近做的WPF项目中,需要一个C#下的Json实现. 在Json的官网http://www.json.org/中查找,可见C#的Json工具主要有如下: 尝试了排在最前面的fastJSON,反序列化时 ...

  2. .Net利用Newtonsoft进行解析Json的快捷方法

    现在异构系统之间的数据交换多采用Json格式 .Net如何快捷地解析Json和将Object转换成json呢? 1.利用Newtonsoft解析Json字符串 在百度上查找资料,利用Newtonsof ...

  3. json解析json字符串时候,数组必须对应jsonObjectArray,不能对应JsonObject。否则会解析错误。

    json第三方解析json字符串时候,json数组必须对应jsonObjectArray,不能对应JsonObject.->只要是[]开头的都是json数组字符串,就要用jsonArray解析 ...

  4. Json转model对象,model转json,解析json字符串

    GitHub链接: https://github.com/mozhenhau/D3Json D3Json 通过swift的反射特性,把json数据转换为model对象,本类最主要是解决了其他一般jso ...

  5. 一、JSON解析与字符串化

    JSON.stringify() 序列化对象.数组或原始值 语法:JSON.stringify(o,filter,indent) o,要转换成JSON的对象.数组或原始值 filter,指定要序列化的 ...

  6. c# 使用Newtonsoft.Json解析JSON数组

    一.获取JSon中某个项的值 要解析格式: [{"VBELN":"10","POSNR":"10","RET_ ...

  7. C# Json解析Json = "{\"EX_RETURN\":[{\"MATNR\":\"test\"}] }";

    string jtext = "{\"jiangsu\":[{\"wuxi\":\"无锡\"},{\"suzhou\&q ...

  8. 认识Json解析json生成json

    .markdown-body hr::after,.markdown-body::after { clear: both } .loopLine,.messageLine0 { } .markdown ...

  9. Newtonsoft.Json解析json字符串和写json字符串

    写: StringWriter sw = new StringWriter(); JsonWriter writer = new JsonWriter(sw); //如果报错则使用JsonWriter ...

随机推荐

  1. Latex感想

    看人家,一个小女生,被导师逼着,首先对电脑方面理解不多,3天时间,latex已经把Paper框架建立起来,我可以说我自愧不如吗?德鲁克<卓有成效的管理者>说的一次干一件事情,<冬吴相 ...

  2. vtk保存图像

    vtkWindowToImageFilter * wif = vtkWindowToImageFilter::New(); vtkBMPWriter *bmpw = vtkBMPWriter::New ...

  3. java remote debug parameters

    java -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n

  4. SVN Cornerstone 报错信息 xcodeproj cannot be opened because the project file cannot be parsed.

    svn点击update 之后,打开xcode工程文件,会出现  xxx..xcodeproj  cannot be opened becausethe project file cannot be p ...

  5. sqlldr

    1.字符集 sqlldr可以指定读取的文件的字符集,如果数据库为gbk,读取的文件为utf-8,这个时候就需要指定字符集 load data CHARACTERSET 'UTF8' 2.sqlldr导 ...

  6. AngularJS-chapter2-7-前端路由

    Form表单提交会导致页面之间的切换,没法实现单页应用 Ajax请求不会留下History记录(在后台管理系统,没有后台历史记录还可以) ,但在网络型应用或门户型应用(用户没有办法给改页面加标签或分享 ...

  7. IS A 和 HAS A的区别

    IS A:一般是用作继承或者接口类.比如:中国人和外国人都是人,重点在:是一个... . HAS A:一般用作对象和他的成员的从属关系.比如:中国人和外国人都有眼睛.耳朵.嘴巴.重点在:有一个... ...

  8. Foundation框架—日期类(NSDate)

    一 时间类NSDate .创建一个日期对象     NSDate *date1 = [[NSDate alloc] init]; //创建了一个当前的时间点     NSDate *date2 = [ ...

  9. oracle 触发器学习

    触发器使用教程和命名规范 目  录触发器使用教程和命名规范 11,触发器简介 12,触发器示例 23,触发器语法和功能 34,例一:行级触发器之一 45,例二:行级触发器之二 46,例三:INSTEA ...

  10. 在指定时间干,必须干(kbmmw 中的事件调度)

    从去年开始,kbmmw 慢慢增加内涵,除了完善各种服务外,陆续增加和扩展了作为一个中间件必须有的功能, 例如,权限管理.日志系统.调度系统.内存调试等功能. 今天给大家介绍一下kbmmw 的调度事件, ...