• cjson 增强对逗号处理


    https://sourceforge.net/projects/cjson/

    解析JSON比较好的轻量级工具,使用比较方便,今天测试发现有些JSON解析失败,但其他工具可以正常解析。

    跟踪发现是cJSON对最后一个逗号分隔处理不足。譬如如下:

    {"liveList":[{"name":"123",},],"code":"0",}

    },]标识前面的逗号就会处理错误,理论上是空对象。

    修改代码cJSon.c

    测试代码:

    int main(int argc, char * argv[])
    {
         char * buff = "{"code":"0","isPreview":"0","isADFreeFlag":"1","logincode":"1014","titleName":"","nodeName":"CCTV2","objType":"live","isAudio":"false","audioDesc":"??:????|nodeId=10080903","playUrl":"http://hls.cmvideo.cn:8088/WqkB2MJM359QHiQ2ShzkitfOjzdoiTz8MF+tjo3OiT1HFopoXQNYHgnkuOCcfZeS+VKurfyXjDfwlpH2/E2GcIPjOjisQkuoQ/rua4ZnuCEbgl1aN4DvlGHKCjETOnEQ/rl3/iqecLI7ukacQKRtCb8dCBxtJ2UflZxWNfzYsvABT2DGlQenXBXeeQFMN3gifppTiH9hGcZMozYca2ECqvx0QgZGyDEbJbCTDmOr5zp9sGGBQ/0M3pP0rFOS68Dy/cctv2_49.sdp.m3u8?ec=1","param":"contentId=60098984520150511028;nodeId=10242984;objType=live;","img":"","uc":"","mt":"","ucmax":"","dlnaRate":"","keyword":"","livePlayback":"true","liveList":[{"sTime":"00:01","eTime":"00:15","name":"?????",},{"sTime":"00:15","eTime":"01:12","name":"????",},{"sTime":"01:12","eTime":"02:13","name":"?????",},{"sTime":"02:13","eTime":"03:11","name":"??",},{"sTime":"03:11","eTime":"03:54","name":"????",},{"sTime":"03:54","eTime":"04:36","name":"????",},{"sTime":"04:36","eTime":"05:07","name":"????",},{"sTime":"05:07","eTime":"06:10","name":"???",},{"sTime":"06:10","eTime":"07:00","name":"???",},{"sTime":"07:00","eTime":"09:00","name":"????",},{"sTime":"09:00","eTime":"10:05","name":"????",},{"sTime":"10:05","eTime":"10:40","name":"????",},{"sTime":"10:40","eTime":"11:10","name":"????",},{"sTime":"11:10","eTime":"11:28","name":"????",},{"sTime":"11:28","eTime":"11:50","name":"????",},{"sTime":"11:50","eTime":"12:30","name":"??????",},{"sTime":"12:30","eTime":"13:21","name":"????",},{"sTime":"13:21","eTime":"14:33","name":"????",},{"sTime":"14:33","eTime":"15:28","name":"??????",},{"sTime":"15:28","eTime":"16:03","name":"?????",},{"sTime":"16:03","eTime":"16:29","name":"????",},{"sTime":"16:29","eTime":"17:11","name":"????",},{"sTime":"17:11","eTime":"17:44","name":"????",},{"sTime":"17:44","eTime":"18:29","name":"???",},{"sTime":"18:29","eTime":"18:52","name":"????",},{"sTime":"18:52","eTime":"19:25","name":"????",},{"sTime":"19:25","eTime":"20:00","name":"????",},{"sTime":"20:00","eTime":"20:30","name":"????",},{"sTime":"20:30","eTime":"21:20","name":"??????",},{"sTime":"21:20","eTime":"21:56","name":"?????",},{"sTime":"21:56","eTime":"22:30","name":"??????",},{"sTime":"22:30","eTime":"23:10","name":"??????",},{"sTime":"23:10","eTime":"23:43","name":"?????",},{"sTime":"23:43","eTime":"23:59","name":"?????",},{"sTime":"23:59","eTime":"23:59","name":"?????",},],"preparam":"","nextparam":"","subList":[],"sTime":"20:00","eTime":"20:30","curDay":"","supportRate":"rate5=;rate4=50_8;rate3=49_8;rate2=;rate1=48_8;","matchedRate":"rate3",}";
    
            printf("################,start  json:%s   
    ",buff);
                        
            cJSON *root;
            root = cJSON_Parse(buff);
    
            if (!root)
            {
                printf("######################!!!!!!!!!!!!!!!!!!!!!!!!!!Error before: [%s]
    ",cJSON_GetErrorPtr());
                return -1;
            }
            
                printf("################end json:
    ");
    
      return 0;
    }
  • 相关阅读:
    最长上升子序列(实验回顾)
    数据库应用开发一、vs
    全文检索
    mangtomant 增删改查
    django
    SQLAlchemy 增删改查 一对多 多对多
    Flask-Sqlalchemy—常用字段类型说明
    flask
    文件下载
    python连接mongodb
  • 原文地址:https://www.cnblogs.com/iclk/p/4496761.html
Copyright © 2020-2023  润新知