2 qq 34904510 qq_34904510 于 2016.09.06 10:48 提问

JSON后台解析InfoTitle

{
"rm": {
"pager": {
"currentPage": 1,
"pageSize": 10,
"totalSize": 7,
"totalPage": 1,
"hasFirst": false,
"hasPrevious": false,
"hasNext": false,
"hasLast": false,
"startNum": 0
},
"data": [
{
"InfoTitle": "毕节交警为你规划线路去百里杜鹃这样走最近",
"TopFlag": true,
"RoadId": null,
"PublishTime": 1458546889000,
"PublishState": 2,
"UpdateTime": 1458546837000,
"InfoTypeVal": "陆路资讯",
"UserId": 25,
"TopFlagCreateTime": null,
"InfoChildTypeVal": "实时新闻",
"username": null,
"CreateTime": 1457665668000,
"ID": 341,
"InfoChildType": 2,
"InfoPageObjId": "959ca1d9-200d-4c81-b9e4-62606984e3f0",
"InfoType": 1,
"PublishStateVal": "已发布"
},
{
"InfoTitle": "近期往返花溪 四趟公交线路临时调整",
"TopFlag": true,
"RoadId": null,
"PublishTime": 1458292331000,
"PublishState": 2,
"UpdateTime": 1458292328000,
"InfoTypeVal": "陆路资讯",
"UserId": 1,
"TopFlagCreateTime": null,
"InfoChildTypeVal": "实时新闻",
"username": "admin1",
"CreateTime": 1458290674000,
"ID": 354,
"InfoChildType": 2,
"InfoPageObjId": "2631631c-c048-40be-8e93-522fcb8bcdec",
"InfoType": 1,
"PublishStateVal": "已发布"
}
]
},
"rmsg": "查询成功!",
"rc": 0
}
要在后台解析到InfoTitle怎么解析....

5个回答

bdmh
bdmh   Ds   Rxr 2016.09.06 10:55

如果是Java,可以直接用JSONObject解析成json对象,然后按照节点名字读取,或者使用gson包,直接转为结构一样的对象,使用更方便

sinat_36057974
sinat_36057974   2016.09.06 11:08

我也遇到了同样的问题,还望指教怎么解决?
@RequestMapping(value = "insertDetails")
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public void insertDetails(
@RequestBody List lisRecInfoDetailsObjs,
@RequestParam(required = true , value ="examinationId")Integer examinationId,
@RequestParam(required = true , value ="lisRecId")Integer lisRecId,
@RequestParam(required = false , value ="userId")Integer userId,
@RequestParam(required = true , value ="startTime")Date startTime,
@RequestParam(required = true , value ="endTime")Date endTime,
@RequestParam(required = true , value ="score")Integer score,
@RequestParam(required = true , value ="totalQuestion")Integer totalQuestion,
@RequestParam(required = true , value ="correctQuestion")Integer correctQuestion,
@RequestParam(required = true , value ="errorQuestion")Integer errorQuestion,
@RequestParam(required = true , value ="completeness")Integer completeness,
HttpServletRequest request, HttpServletResponse response) {
User logUser = this.getLoginUser();
这样写可以吗

of214
of214   2016.09.06 12:51

定义一个对象,然后使用fastjson转换一下就可以了,看些这篇文章http://58coding.com/article/detail/24637472273072297

u013829202
u013829202   Rxr 2016.09.06 13:22

apach google都提供了json的一些工具包。 建议用gson直接解析成对象。 方便点

niaonao
niaonao   Rxr 2016.09.06 15:04

意思就是解析json 数据



例子如下:
{
  "statusCode": "200",
  "data": [
    {
        "havaTeam": "1"
    },

    {
        "user": {
              "id": 9615,
              "birthday": "",
              "username": "Curse.",
              "sex": "",
              "remark": "",
              "sourceuserid": "os0WpxFQZK2PPtDlpphEjzRE5c40",
              "firstlogtime": "",
              "usersource": "",
              "headimgurl": "http://wx.qlogo.cn/mmopen/iazJJcMFKX0hRFR6sWRwv50XKErFXsiaiaKWHTS19iaaeIdVMfibJJTXiaqtx7USmbVo8Qc9Gbwuu01jOOqvn76YWVyja3GclqQhm7/0",
              "islock": "0",
              "city": "黑龙江"
          }
     }
     ],

   "msg": ""
}

 和你的一样,就是格式规范了些,
 看起来很多很繁
 其实就是最简单的格式的嵌套
 格式:[{"data":"_data"}]

利用json 相关包处理就行了
json 数据处理同类问题

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!