void FCarAddEdit::ReloadSavedData() { if (this->itemid > 0) { carconclass_->GetCarData(this->itemid, curcardata_, true); controlhandler_->SetValue(this,L"EF_1_brand", curcardata_.Brand); controlhandler_->SetValue(this,L"EF_2_model", curcardata_.Model); controlhandler_->SetValue(this,L"EFN_3_startkm", curcardata_.startkm); controlhandler_->SetValue(this,L"CB_4_fueltypestring", curcardata_.fueltypesstring); controlhandler_->SetValue(this,L"EF_year", curcardata_.year); controlhandler_->SetValue(this,L"EF_licenceplate", curcardata_.licence); controlhandler_->SetValue(this,L"EF_vin", curcardata_.vin); controlhandler_->SetValue(this,L"EF_isurance", curcardata_.isurance); fueltypesselectedarray_.RemoveAll(); for (int i=0; i < pListSelectFuelTypes_->GetItemCount(); i++) { pListSelectFuelTypes_->SetItemChecked(i, false); } IEnumeratorT<int>* enumint = curcardata_.fueltypesarray.GetEnumeratorN(); if (enumint){ int fueltypeid; while (enumint->MoveNext() == E_SUCCESS){ enumint->GetCurrent(fueltypeid); int selecteditemindex = pListSelectFuelTypes_->GetItemIndexFromItemId(fueltypeid); if (selecteditemindex > -1) { pListSelectFuelTypes_->SetItemChecked(selecteditemindex, true); fueltypesselectedarray_.Add(fueltypeid); } } } delete enumint; } }
void Json::Clear(void){ if (__values.GetCount() > 0){ MapEntryT<String, Object* >* current; IEnumeratorT<MapEntryT<String, Object* >* >* enumerator = __values.GetEnumeratorN(); while(enumerator->MoveNext() == E_SUCCESS){ enumerator->GetCurrent(current); String key = current->GetKey(); Object* o = current->GetValue(); if (o != NULL){ delete o; } } __values.RemoveAll(); delete enumerator; } }
String Json::Stringify(){ String json = __type == AArrayType ? "{" : "["; IEnumeratorT<MapEntryT<String, Object* >* >* enumerator = __values.GetEnumeratorN(); int length = __values.GetCount(); int index = 0; MapEntryT<String, Object* >* current; while(enumerator->MoveNext() == E_SUCCESS){ enumerator->GetCurrent(current); json.Append(StringifyValue(current)); if (++index < length) json.Append(","); } json.Append( __type == AArrayType ? "}" : "]"); delete enumerator; return json; }
//Recursively traverse IJsonValue obtained by parser (using ParseN) void ProjectGiraffeTab1::TraverseFunction(IJsonValue* pValue) { TryReturnVoid(_tableView, "tableView is null"); TryReturnVoid(pValue, "input jsonvalue pointer is null"); User *dummyUser = new User(); dummyUser->setUsername(L"CS210 Student"); Graffiti *lastCreatedGraffiti = NULL; switch (pValue->GetType()) { case JSON_TYPE_OBJECT: { JsonObject* pObject = static_cast< JsonObject* >(pValue); IMapEnumeratorT< const String*, IJsonValue* >* pMapEnum = pObject->GetMapEnumeratorN(); while (pMapEnum->MoveNext() == E_SUCCESS) { AppLog("IN JSON OBJECT"); const String* key = null; IJsonValue* value = null; pMapEnum->GetKey(key); pMapEnum->GetValue(value); String* pListKey = new (std::nothrow) String(*key); _pJsonKeyList->Add(*pListKey); AppLog("Key: %ls", pListKey->GetPointer()); if(pListKey->Equals("message",true)){ AppLog("Message received"); lastCreatedGraffiti = new Graffiti(); lastCreatedGraffiti->setUser(dummyUser); JsonString* pVal = static_cast< JsonString* >(value); String* pListValue = new (std::nothrow) String(*pVal); lastCreatedGraffiti->setText(String(*pListValue)); _items->Add(lastCreatedGraffiti); AppLog("message : %ls", lastCreatedGraffiti->text().GetPointer()); } else if (value && pListKey->Equals("latitude", true)) { JsonNumber *jsonNum = static_cast<JsonNumber *>(value); Double *latValue = static_cast<Double *>(jsonNum); if (latValue && lastCreatedGraffiti) { lastCreatedGraffiti->setLatitude(latValue->ToFloat()); AppLog("latitude : %f", lastCreatedGraffiti->longitude()); } } else if (value != NULL && pListKey->Equals("longitude", true)) { JsonNumber *jsonNum = static_cast<JsonNumber *>(value); Double *lonValue = static_cast<Double *>(jsonNum); if (lonValue && lastCreatedGraffiti) { lastCreatedGraffiti->setLongitude(lonValue->ToFloat()); AppLog("longitude : %f", lastCreatedGraffiti->longitude()); } } } delete pMapEnum; } break; case JSON_TYPE_STRING: { JsonString* pVal = static_cast< JsonString* >(pValue); if (_isArray == 0) { String* pStr = new (std::nothrow) String(*pVal); _pValueList->Add(*pStr); } } break; case JSON_TYPE_ARRAY: { JsonArray* pJsonArray = static_cast< JsonArray* >(pValue); pJsonArray->GetCount(); IEnumeratorT< IJsonValue* >* pEnum = pJsonArray->GetEnumeratorN(); while (pEnum->MoveNext() == E_SUCCESS) { IJsonValue* pValue = null; pEnum->GetCurrent(pValue); if ((pValue->GetType() == JSON_TYPE_STRING) || (pValue->GetType() == JSON_TYPE_NUMBER) || (pValue->GetType() == JSON_TYPE_BOOL) || (pValue->GetType() == JSON_TYPE_NULL)) { _isArray = 1; } TraverseFunction(pValue); } delete pEnum; } break; case JSON_TYPE_NUMBER: { JsonNumber* pVal = static_cast< JsonNumber* >(pValue); String* pStr = new (std::nothrow) String((pVal->ToString())); if (_isArray == 0) _pValueList->Add(*pStr); } break; case JSON_TYPE_BOOL: { String* pStr = null; JsonBool* pVal = static_cast< JsonBool* >(pValue); if (*pVal == true) pStr = new (std::nothrow) String("true"); else pStr = new (std::nothrow) String("false"); if (_isArray == 0) _pValueList->Add(*pStr); } break; case JSON_TYPE_NULL: { String* pStr = null; pStr = new (std::nothrow) String("null"); if (_isArray == 0) _pValueList->Add(*pStr); } break; default: break; } _tableView->UpdateTableView(); }