填 Cocos2dx 的 jsval_to_ccdictionary 坑

 在cocos2dx字典转换nactive的函数jsval_to_ccdictionary,只判断三个类型如果为空导致系统崩溃

以下是修改方法:找到函数底部

else if (JSVAL_IS_STRING(value)) {

           JSStringWrapper valueWapper(JSVAL_TO_STRING(value), cx);

            dict->setObject(String::create(valueWapper.get()), keyWrapper.get());

            //            CCLOG("iterate object: key = %s, value = %s", keyWrapper.get().c_str(), valueWapper.get().c_str());

        }

       else if (JSVAL_IS_NUMBER(value)) {

           double number = 0.0;

           JSBool ok = JS_ValueToNumber(cx, value, &number);

           if (ok) {

                dict->setObject(Double::create(number), keyWrapper.get());

                //                CCLOG("iterate object: key = %s, value = %lf", keyWrapper.get().c_str(), number);

            }

        }

       else if (JSVAL_IS_BOOLEAN(value)) {

           JSBool boolVal = JS_FALSE;

           JSBool ok = JS_ValueToBoolean(cx, value, &boolVal);

           if (ok) {

                dict->setObject(Bool::create(boolVal), keyWrapper.get());

                //                +CCLOG("iterate object: key = %s, value = %d", keyWrapper.get().c_str(), boolVal);

            }

        }else if (value.isNullOrUndefined())

        {

            // CCASSERT(false, "not isNull supported type");//value.isNullOrUndefined 这个需要判断,否则插入为空值系统崩溃。

            dict->setObject(String::create(""), keyWrapper.get());

            

            

        }

        

       else   {

            CCASSERT(false,"not supported type");

        }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值