/** * This parses a javascript objet from the content */ void JSONNode::parseObject(){ if(m_debug) cout<<"[parseObject] "<<m_start<<" "<<m_end<<endl; int start=m_start; int end=m_end; while(m_content[start]!='{') start++; while(m_content[end]!='}') end--; start++; end--; while(start<=end){ // find the opening " for the key int findNextKey=start; while(m_content[findNextKey]!='"' && findNextKey<=end){ findNextKey++; } // no more keys if(m_content[findNextKey]!='"'){ if(m_debug) cout<<"[parseObject] no more keys"<<endl; break; } if(m_debug){ cout<<"[parseObject] findNextKey -> "<<findNextKey<<" "<<m_content[findNextKey]<<endl; cout<<"[parseObject] find key"<<endl; } JSONNode key; pullString(&key,start); // find the first non-white-space character int firstNextSymbol=key.getEnd(); firstNextSymbol++; // TODO: this code will work with "key"::: "Value" but should not while(m_content[firstNextSymbol]==' '||m_content[firstNextSymbol]=='\t'||m_content[firstNextSymbol]=='\n' || m_content[firstNextSymbol]==':'){ firstNextSymbol++; } if(m_debug) cout<<"[parseObject] find value"<<endl; JSONNode value; pullContent(&value,firstNextSymbol); start=value.getEnd(); start++; // Skip the ',' // TODO: this code will work with "key",,,, but should not while(m_content[start]==' '||m_content[start]=='\t'||m_content[start]=='\n' || m_content[start]==','){ start++; } m_associativeKeyContent.push_back(key); m_associativeValueContent.push_back(value); } }
void JSONNode::parseArray(){ if(m_debug) cout<<"[parseArray] "<<m_start<<" "<<m_end<<endl; int start=m_start; int end=m_end; while(m_content[start]!='[') start++; while(m_content[end]!=']') end--; start++; end--; while(start<=end){ // find the opening " for the key int findNextKey=start; while(!isDigitSymbol(m_content[findNextKey]) && m_content[findNextKey]!='{' && m_content[findNextKey]!='[' && m_content[findNextKey]!='"' && findNextKey<=end){ findNextKey++; } // no more keys if(!isDigitSymbol(m_content[findNextKey]) && m_content[findNextKey]!='{' && m_content[findNextKey]!='[' && m_content[findNextKey]!='"' ){ if(m_debug) cout<<"[parseObject] no more values"<<endl; break; } if(m_debug) cout<<"[parseArray] findNextKey -> "<<findNextKey<<" "<<m_content[findNextKey]<<endl; // find the first non-white-space character int firstNextSymbol=start; while(m_content[firstNextSymbol]==' '||m_content[firstNextSymbol]=='\t' ||m_content[firstNextSymbol]=='\n'){ firstNextSymbol++; } if(m_debug) cout<<"[parseArray] find value"<<endl; JSONNode value; pullContent(&value,firstNextSymbol); start=value.getEnd(); start++; // Skip the ',' // TODO: this code will work with "key",,,, but should not while(m_content[start]==' '||m_content[start]=='\t'||m_content[start]=='\n' || m_content[start]==','){ start++; } m_arrayContent.push_back(value); } }