微信开发之工具类
2016-04-05 10:42
399 查看
微信开发过程中少不了一些数据类型的转换,其中json格式用的最多,所以就有了下面这一段代码:
当然,要引用Microsoft.JScript。
期间也要用到时间戳之间的转换:
还有一些常用的方法,例如,字符串转数字:
public static string toJson(this object jsonObj) { try { return new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(jsonObj); } catch (Exception ex) { LogHelper.write("toJson:" + ex.Message + ",data:" + DateTime.Now); return null; } } public static T fromJson<T>(this string json) where T : class { return new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<T>(json); }
当然,要引用Microsoft.JScript。
期间也要用到时间戳之间的转换:
public static int dateToInt(this DateTime time) { int intResult = 0; System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); intResult = Convert.ToInt32((time - startTime).TotalSeconds); return intResult; } public static DateTime intToDate(this int timeStamp) { DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long lTime = long.Parse(timeStamp + "0000000"); TimeSpan toNow = new TimeSpan(lTime); return dateTimeStart.Add(toNow); }
还有一些常用的方法,例如,字符串转数字:
public static int toInt(this string str) { int result = 0; int.TryParse(str, out result); return result; }
相关文章推荐
- 微信js-sdk,选择图片,上传,下载到本地,php服务端
- 关于微信支付由H5页面修改为类似于微信支付手机充值的效果
- 很难吗?教你三天精仿一个跨平台的微信
- 如果没有微信,你的日子就过不下去了么?
- 搜一搜、扫一扫,关注Rayvision官方微信即送渲染费!
- 微信、APP、HTML5之间的对比
- 微信公众号设计规划与管理
- Flex简单小程序
- 搭建属于自己的ngrok服务器,实现内网穿透,外网访问内网,可本地开发微信不需要上传服务器
- 分别嵌入 新浪微博、QQ、微信 做第三方授权登录 获取到头像 昵称等信息
- andorid 练习微信登陆
- 支付宝,微信接入需要注意点,招行银企直连接入注意点
- caoliu 官网公众号yesxiaocao 1024 caoliushequ 也是小草
- [编程题] 微信红包
- PHP--仿微信, 通过登陆者用户名显示好友列表,显示头像和昵称
- java微信开发API解析(二)-获取消息和回复消息
- 一个简单的英汉词典小程序
- 使用ShareSDK完成第三方(QQ、微信、微博)登录和分享
- 二、微信公众号请求交互方式
- 微信公众号API返回不可打印字符的处理。