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++;
}
}
LibJson數據解析方法
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.