EXPORT char * Z$F_J2F (char * sz) { int len = strlen(sz); char * sz_result = (char *) ib_util_malloc (len); unescapeJSON(sz,sz_result); return sz_result; }
std::string getJSONValue(const Value &v) { std::stringstream ret; switch(v.GetType()) { case kNullType: ret << "null"; break; case kFalseType: ret << "false"; break; case kTrueType: ret << "true"; break; case kObjectType: break; case kArrayType: break; case kStringType: ret << std::string("'") << unescapeJSON(v.GetString()) << std::string("'"); break; case kNumberType: { char buf[1024]; if(v.IsInt()) { ret << v.GetInt(); } else if(v.IsDouble()) { ret << std::setprecision(16) << v.GetDouble(); } } break; } return ret.str(); }
void JSONModelLoader::loadObject(Lexer *lexer,string nameInParent,KMFContainer *parent,vector<KMFContainer*> *roots ,vector<ResolveCommand*> *commands) { Logger::Write(Logger::DEBUG_MICROFRAMEWORK, "loadObject "+nameInParent); Token currentToken = lexer->nextToken(); KMFContainer *currentObject=NULL; if(currentToken.tokenType == VALUE) { if(currentToken.value.compare("eClass") == 0){ lexer->nextToken(); //unpop : currentToken = lexer->nextToken(); //Two step for having the name string name = currentToken.value; if(factory == NULL) { Logger::Write(Logger::ERROR," JSONModelLoader::loadObject the Default Factory is NULL WTF"); throw std::string( " JSONModelLoader::loadObject the Default Factory is NULL WTF" ); } currentObject = factory->create(name); Logger::Write(Logger::DEBUG_MICROFRAMEWORK, "Create "+name); if(currentObject == NULL) { throw std::string(" JSONModelLoader::loadObject the Default Factory failed to build "+name ); } if(parent == NULL){ roots->push_back(currentObject); } string currentNameAttOrRef; bool refModel = false; currentToken = lexer->nextToken(); while(currentToken.tokenType != EOF){ if(currentToken.tokenType == LEFT_BRACE) { loadObject(lexer, currentNameAttOrRef, currentObject, roots, commands); } /* if(currentToken.tokenType == COMMA){ //ignore } */ if(currentToken.tokenType == VALUE){ if(currentNameAttOrRef.empty()) { currentNameAttOrRef = currentToken.value; } else { if(refModel) { ResolveCommand *resolvecommand = new ResolveCommand(roots, currentToken.value, currentObject, currentNameAttOrRef); commands->push_back(resolvecommand); } else { any json =string(unescapeJSON(currentToken.value)); currentObject->reflexiveMutator(SET, currentNameAttOrRef,json ,false,false) ; currentNameAttOrRef.clear(); } } } if(currentToken.tokenType == LEFT_BRACKET){ currentToken = lexer->nextToken(); if(currentToken.tokenType == LEFT_BRACE){ loadObject(lexer, currentNameAttOrRef, currentObject, roots, commands) ; } else { refModel = true; //wait for all ref to be found if(currentToken.tokenType == VALUE){ ResolveCommand *resolvecommand = new ResolveCommand(roots, currentToken.value, currentObject, currentNameAttOrRef); commands->push_back(resolvecommand); } } } if(currentToken.tokenType == RIGHT_BRACKET){ currentNameAttOrRef.clear(); refModel = false ; } if(currentToken.tokenType == RIGHT_BRACE){ if(parent != NULL) { any json =currentObject; Logger::Write(Logger::DEBUG_MICROFRAMEWORK, "PARENT ADD" +nameInParent); parent->reflexiveMutator(ADD, nameInParent,json ,false,false) ; } return; //go out } currentToken = lexer->nextToken(); } }else { throw std::string("Bad Format / eClass att must be first"); //TODO save temp att } } else { throw std::string("Bad Format"); } }