void HelloWorld::ParseJSON(JSONNode *n,CCMutableArray<CCObject *> *array,CCMutableDictionary<std::string,CCObject *> *dic,CCMutableDictionary<std::string,CCObject *> *dataDicLast)
{
if(n==NULL)
{
printf("擦 什么都没有你简析个屁了呀!滚蛋\n");
}
JSONNode::iterator iterator=n->begin();
while (iterator!=n->end())
{
//-------------------获取key
json_string stringKeyJson=iterator->name();
const string stdKeyString=to_std_string(stringKeyJson);
//printf("key====%s",stdKeyString.c_str());
//-------------------获取Value
const char stringValueJson=iterator->type();
//printf("type===%d\n",stringValueJson);
if(iterator->type()==JSON_ARRAY && stdKeyString!="")
{
CCMutableArray<CCObject *> *tempArray=new CCMutableArray<CCObject *>;
ParseJSON(&(*iterator),tempArray,NULL,NULL);
dataDicLast->setObject(tempArray, stdKeyString.c_str());
tempArray->release();
}
else if(iterator->type()==JSON_ARRAY)
{
CCMutableArray<CCObject *> *tempArray=new CCMutableArray<CCObject *>;
ParseJSON(&(*iterator),tempArray,NULL,NULL);
array->addObject(tempArray);
tempArray->release();
}
else if(iterator->type()==JSON_STRING && stdKeyString!="")
{
json_string valueJString=iterator->as_string();
std::string ValueCstring=to_std_string(valueJString);
CCString *valueString=new CCString(ValueCstring.c_str());
dataDicLast->setObject(valueString, stdKeyString.c_str());
valueString->release();
}
else if(iterator->type()==JSON_STRING)
{
json_string valueJString=iterator->as_string();
std::string ValueCstring=to_std_string(valueJString);
CCString *valueString=new CCString(ValueCstring.c_str());
array->addObject(valueString);
valueString->release();
}
else if(iterator->type()==JSON_NODE && stdKeyString!="")
{
CCMutableDictionary<std::string,CCObject *> *tempDic=new CCMutableDictionary<std::string,CCObject *>;
ParseJSON(&(*iterator),NULL,NULL,tempDic);
dataDicLast->setObject(tempDic, stdKeyString.c_str());
tempDic->release();
}
else
{
CCMutableDictionary<std::string,CCObject *> *tempDic=new CCMutableDictionary<std::string,CCObject *>;
ParseJSON(&(*iterator),NULL,NULL,tempDic);
dic->setObject(tempDic, stdKeyString.c_str());
tempDic->release();
}
iterator++;
}
}
转载于:https://blog.51cto.com/wangxu254/1313838