欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > > 文章正文

new JSONArray(List).tostring()问题,jsonarray.tostring

来源: javaer 分享于  点击 11190 次 点评:225

new JSONArray(List).tostring()问题,jsonarray.tostring


不同的手机系统版本生成string结果不一样。

高系统系统(5.1)设备,转换之后是json单元组成的jsonarray。

array.toString=[{"channelname":"DIALOG NOW","tsavailable":"0","hasprogram":"0",
 "totalcount":"52","filename":"..\/images\/markurl\/mark_1482907604038.png","channelcode":"ch00000000000000001139","mixno":"1","ratingid":"1",
 "columncode":"010100","npvravailable":"0","timeshiftenable":"0","tvodavailable":"0","tvodenable":"0"},{"channelname":"RUPAVAHINI","tsavailable":"120",
 "hasprogram":"1","totalcount":"52","filename":"..\/images\/markurl\/mark_1446201343209.png","channelcode":"ch00000000000000001036","mixno":"2","ratingid":"1",
 "columncode":"010100","npvravailable":"0","timeshiftenable":"1","tvodavailable":"1","tvodenable":"1"},

低系统设备(4.4):

array.tostring=["{tsavailable=0, hasprogram=0, totalcount=52, channelname=DIALOG NOW, columncode=010100, tvodavailable=0,
 filename=..\/images\/markurl\/mark_1482907604038.png, npvravailable=0, tvodenable=0, ratingid=1, channelcode=ch00000000000000001139,
 mixno=1, timeshiftenable=0}","{tsavailable=120, hasprogram=1, totalcount=52, channelname=RUPAVAHINI, columncode=010100, tvodavailable=1,
 filename=..\/images\/markurl\/mark_1446201343209.png, npvravailable=0, tvodenable=1, ratingid=1, channelcode=ch00000000000000001036, mixno=2, 
 timeshiftenable=1}","{tsavailable=120, hasprogram=1, totalcount=52, channelname=CHANNEL EYE, columncode=010100, tvodavailable=1, 
 filename=..\/images\/markurl\/mark_1446201416620.png, npvravailable=0, tvodenable=1, ratingid=1,
 channelcode=ch00000000000000001037, mixno=3, timeshiftenable=1}","{tsavailable=120, hasprogram=1, totalcount=52, channelname=IT...

对于含有“=”号不规范的json字符串,只能一点点分离解析,对于标准的json格式字符串直接转化。

if(str.contains("="))
{
    Map<String, Object> valueMap = new HashMap<String, Object>();
    String newstr = str.substring(1,str.length() - 1);//去掉首尾
    // LogEx.i("lxl","newstr:" + newstr);
    String [] splitArr = newstr.split(",");
    for(int j = 0;j < splitArr.length; j++)
    {
        splitArr[j] = splitArr[j].trim();//去掉首尾空格
        String [] valueArr = splitArr[j].split("=");
        String key = valueArr[0];
        Object value;
        if(valueArr.length >= 2)//防止空数据异常
        {
            value = valueArr[1];
        }
        else{
            value = "";
        }
        // LogEx.i("lxl","key,value:" + key + "," + value);
        valueMap.put(key,value);
   }

    praseChannel(valueMap);
}
else
{
    JSONObject obj = array.getJSONObject(i);
    Map<String, Object> map = getMap(obj);
    praseChannel(map);
}


相关文章

    暂无相关文章

用户点评