首页 新闻 搜索 专区 学院

JSON数据分组解析

0
悬赏园豆:50 [已解决问题] 解决于 2016-11-14 16:51

1.这是一串JSON数据,
[{"CAMPSEG_ID":"2015091715592558","CAMPSEG_NAME":"推送VVM功能对苹果用户","POSTER_ID":"CPCC_POSTER_20150812224606_00039","POSTER_NAME":"toolbar-翻倍乐套餐推广","CONTACT_ID":"CPCC_ADV_20150811223540_00032","CONTACT_NAME":"toolbar图文营销位","months":"2016-07","CNMonths":"2016年-07月","totalClickCost":27,"totalExposureCost":2.24,"totalMarketingCost":0,"costs":29.24,"EXPOSURE_TIMES":2,"CLICK_TIMES":9},{"CAMPSEG_ID":"2015090212222980","CAMPSEG_NAME":"toolbar-合约减现-2","POSTER_ID":"CPCC_POSTER_20150812225935_00041","POSTER_NAME":"toolbar-飞信业务推广","CONTACT_ID":"CPCC_ADV_20150811223540_00032","CONTACT_NAME":"toolbar图文营销位","months":"2016-07","CNMonths":"2016年-07月","totalClickCost":237,"totalExposureCost":24.64,"totalMarketingCost":0,"costs":261.64,"EXPOSURE_TIMES":22,"CLICK_TIMES":79},{"CAMPSEG_ID":"2015091014252892","CAMPSEG_NAME":"toolbar-星级用户购4G手机优惠","POSTER_ID":"CPCC_POSTER_20150812232552_00043","POSTER_NAME":"toolbar-手机报业务推广","CONTACT_ID":"CPCC_ADV_20150811223657_00033","CONTACT_NAME":"toolbar文字营销位","months":"2016-07","CNMonths":"2016年-07月","totalClickCost":8.7,"totalExposureCost":54.3,"totalMarketingCost":55,"costs":118,"EXPOSURE_TIMES":15,"CLICK_TIMES":87},{"CAMPSEG_ID":"2015091014252892","CAMPSEG_NAME":"toolbar-星级用户购4G手机优惠","POSTER_ID":"CPCC_POSTER_20150910224840_00094","POSTER_NAME":"toolbar-星级用户购机送话费","CONTACT_ID":"CPCC_ADV_20150811223657_00033","CONTACT_NAME":"toolbar文字营销位","months":"2016-07","CNMonths":"2016年-07月","totalClickCost":0.6,"totalExposureCost":39.82,"totalMarketingCost":0,"costs":40.42,"EXPOSURE_TIMES":11,"CLICK_TIMES":6},{"CAMPSEG_ID":"2015070115303553","CAMPSEG_NAME":"邮箱0701","POSTER_ID":"CPCC_POSTER_20160223164953_00453","POSTER_NAME":"1005233","CONTACT_ID":"CPCC_ADV_20150625224935_00022","CONTACT_NAME":"猜你喜欢","months":"2016-07","CNMonths":"2016年-07月","totalClickCost":155.4,"totalExposureCost":195.3,"totalMarketingCost":55,"costs":405.7,"EXPOSURE_TIMES":63,"CLICK_TIMES":74},{"CAMPSEG_ID":"2015091014252892","CAMPSEG_NAME":"toolbar-星级用户购4G手机优惠","POSTER_ID":"CPCC_POSTER_20150812232745_00044","POSTER_NAME":"toolbar-精品电子书推广","CONTACT_ID":"CPCC_ADV_20150811223657_00033","CONTACT_NAME":"toolbar文字营销位","months":"2016-08","CNMonths":"2016年-08月","totalClickCost":1,"totalExposureCost":112.22,"totalMarketingCost":0,"costs":113.22,"EXPOSURE_TIMES":31,"CLICK_TIMES":10},{"CAMPSEG_ID":"2015091715592558","CAMPSEG_NAME":"推送VVM功能对苹果用户","POSTER_ID":"CPCC_POSTER_20150915195335_00096","POSTER_NAME":"toolbar-积分充话费","CONTACT_ID":"CPCC_ADV_20150811223540_00032","CONTACT_NAME":"toolbar图文营销位","months":"2016-08","CNMonths":"2016年-08月","totalClickCost":24,"totalExposureCost":33.6,"totalMarketingCost":0,"costs":57.6,"EXPOSURE_TIMES":30,"CLICK_TIMES":8},{"CAMPSEG_ID":"2015070115303553","CAMPSEG_NAME":"邮箱0701","POSTER_ID":"CPCC_POSTER_20150625233044_00026","POSTER_NAME":"飞信-召唤小伙伴-4G换机群","CONTACT_ID":"CPCC_ADV_20150625224935_00022","CONTACT_NAME":"猜你喜欢","months":"2016-09","CNMonths":"2016年-09月","totalClickCost":139.2,"totalExposureCost":72.29,"totalMarketingCost":868,"costs":1079.49,"EXPOSURE_TIMES":5,"CLICK_TIMES":56},{"CAMPSEG_ID":"2015091014252892","CAMPSEG_NAME":"toolbar-星级用户购4G手机优惠","POSTER_ID":"CPCC_POSTER_20150812232956_00046","POSTER_NAME":"toolbar-咪咕音乐客户端推广","CONTACT_ID":"CPCC_ADV_20150811223657_00033","CONTACT_NAME":"toolbar文字营销位","months":"2016-09","CNMonths":"2016年-09月","totalClickCost":0.5,"totalExposureCost":50.68,"totalMarketingCost":10,"costs":61.18,"EXPOSURE_TIMES":14,"CLICK_TIMES":5},{"CAMPSEG_ID":"2015070115303553","CAMPSEG_NAME":"邮箱0701","POSTER_ID":"CPCC_POSTER_20150625233044_00026","POSTER_NAME":"飞信-召唤小伙伴-4G换机群","CONTACT_ID":"CPCC_ADV_20160628215934_00013","CONTACT_NAME":"网厅_手机专区_Bannar","months":"2016-10","CNMonths":"2016年-10月","totalClickCost":8.64,"totalExposureCost":69.41,"totalMarketingCost":434,"costs":512.05,"EXPOSURE_TIMES":11,"CLICK_TIMES":2},{"CAMPSEG_ID":"2015092216434870","CAMPSEG_NAME":"竞品类联调测试922","POSTER_ID":"CPCC_POSTER_20160928144745_00571","POSTER_NAME":"反对","CONTACT_ID":"CPCC_ADV_20160930101633_00020","CONTACT_NAME":"专门测试的","months":"2016-10","CNMonths":"2016年-10月","totalClickCost":19.8,"totalExposureCost":429,"totalMarketingCost":3,"costs":451.8,"EXPOSURE_TIMES":55,"CLICK_TIMES":9}]

2.现在我要得到这样的数据格式:

{
months:[{poster_name:costs},{poster_name:costs}],
......

即:
{
2016-10:[{飞信-召唤小伙伴-4G换机群:512.05},{反对:451.8}],
2016-09:[{飞信-召唤小伙伴-4G换机群:1079.49},{toolbar-咪咕音乐客户端推广:61.18}],
......
}

以此类推.....
最好能帮忙直接给出源码,谢谢

请叫我阳大官人的主页 请叫我阳大官人 | 初学一级 | 园豆:32
提问于:2016-11-09 12:04
< >
分享
最佳答案
0

var map = new HashMap();
for(var i=0;i<data.length;i++){
var key = data[i].months;
var newJson = "{'"+data[i].POSTER_NAME+"':'"+data[i].costs+"'}";
var oldJson = map.get(key);
if(oldJson!=null){
newJson = newJson +"," + oldJson;
}
map.put(key,newJson);
}

请叫我阳大官人 | 初学一级 |园豆:32 | 2016-11-14 16:50
其他回答(3)
0

反序列化成对象数组遍历一遍不就完了么?

收获园豆:10
Daniel Cai | 园豆:10424 (专家六级) | 2016-11-09 12:18

不会写,能否上代码呢?

支持(0) 反对(0) 请叫我阳大官人 | 园豆:32 (初学一级) | 2016-11-09 14:41
0

nuget 搜 cyqdata,引入cyq.data

然后通过:Dictionary<string,string> dic= JsonHelper.Split(json);

或者通过:MDataTable dt=MDataTable.CreateFrom(json);

转成表,然后就很好处理了。

收获园豆:30
路过秋天 | 园豆:4763 (老鸟四级) | 2016-11-09 12:34

后端的话是可以,要是前端的话这样不是很麻烦了。

支持(0) 反对(0) seayxu | 园豆:5468 (大侠五级) | 2016-11-09 13:38
0

一个通用的方法:遍历、判断、插入到数组中。

收获园豆:10
seayxu | 园豆:5468 (大侠五级) | 2016-11-09 13:39

嗯,但是我不知道要怎么写。

支持(0) 反对(0) 请叫我阳大官人 | 园豆:32 (初学一级) | 2016-11-09 14:41
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册