json数组解析失败

[{"vehicleNum":"u9c81Q24956","shipDtPlan":Wed Jan 14 14:15:00 CST 2015,"orderCode":"20150117104","originAddress":"345","consigneeTelphone":"","goodsQuantity":234,"consigneePhoneNum":"","userName":"","limitHours":62,"goodsWeight":234,"goodsUnit":"234","driverName":"u5f20u4e09","orderId":104,"createDt":Sat Jan 17 00:00:00 CST 2015,"customerName":"3u989du5934u513fu7ae5","overdueDt":Tue Jan 20 04:15:44 CST 2015,"consigneeName":"","customerPhoneNum":"13000000001","collPayRemark":"","customerCompany":"345","transactor":"","sendTime":Thu Jan 15 00:00:00 CST 2015,"origin":"345 ","orderStatus":2,"deliveryReamrk":"","destination":"","consigneeCompany":"","driverPhoneNum":"13511111111","destinationAddress":"","arriveDtPlan":Sat Jan 17 00:00:00 CST 2015,"goodsName":"rwerw"}, {"vehicleNum":"u9c81Q24956","shipDtPlan":Wed Jan 14 13:25:00 CST 2015,"orderCode":"20150115105","originAddress":"345","consigneeTelphone":"","consigneePhoneNum":"","goodsWeight":234,"goodsUnit":"234","driverName":"u5f20u4e09","orderId":105,"createDt":Thu Jan 15 13:25:25 CST 2015,"customerName":"3u989du5934u513fu7ae5","consigneeName":"","customerPhoneNum":"13000000001","collPayRemark":"","customerCompany":"345","transactor":"","origin":"345 ","orderStatus":1,"destination":"","consigneeCompany":"","deliveryReamrk":"","driverPhoneNum":"13511111111","destinationAddress":"","goodsName":"234234"}]

返回的json是nsstring格式的,用asi接收有乱码,但是用

NSArray *arrlist=[strJson objectFromJSONString];

返回的是null,转换成data 用

ret = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];

也不能转换成数组,本人较菜,望大神不吝赐教。

你的JSON数据是错误的,所以无法转化。这个问题和OC无关

JSON不支持“shipDtPlan”:Wed Jan 14 14:15:00 CST 2015这种形式。日期应该转化为timestamp甚至字符串类型都是可以的

JSON 值可以是:

  • 数字(整数或浮点数)
  • 字符串(在双引号中)
  • 逻辑值(true 或 false)
  • 数组(在方括号中)
  • 对象(在花括号中)
  • null

参考:http://www.w3school.com.cn/json/json_syntax.asp

你需要 jsonlint
http://jsonlint.com/

首先先转换成NSDictionary或者NSArray,然后再去转换对象。
那个字符串可以转化为NSDate对象。

发表评论

电子邮件地址不会被公开。 必填项已用*标注