bool ProductInfo::FromJson(JSON* pJsonNode) { bool bRet = false; if (NameFromJson(pJsonNode) && URLFromJson(pJsonNode) && IDFromJson(pJsonNode)) { JSON *pDisplay = pJsonNode->GetItemByName("Display"); JSON *pLensSeparation = pJsonNode->GetItemByName("LensSeparation"); JSON *pMobilePositon = pJsonNode->GetItemByName("MobilePositon"); JSON *pGlassID = pJsonNode->GetItemByName("GlassID"); JSON *pOS = pJsonNode->GetItemByName("OS"); JSON *pMachineID = pJsonNode->GetItemByName("MachineID"); if (pDisplay && ParseLanguageDisplay(&m_Display, pDisplay) && pGlassID && ParseIDList(&m_AllGlassID, pGlassID)) { if (pLensSeparation && pLensSeparation->Type == JSON_Array && pLensSeparation->GetArraySize() >= 1 && pLensSeparation->GetArraySize() <= 3) { if (pLensSeparation->GetArraySize() == 1) { SetLensSeparation(pLensSeparation->GetArrayNumber(0)); SetLensSeparationMin(pLensSeparation->GetArrayNumber(0)); SetLensSeparationMax(pLensSeparation->GetArrayNumber(0)); } else if (pLensSeparation->GetArraySize() == 2) { SetLensSeparation((pLensSeparation->GetArrayNumber(0) + pLensSeparation->GetArrayNumber(1)) / 2); SetLensSeparationMin(pLensSeparation->GetArrayNumber(0)); SetLensSeparationMax(pLensSeparation->GetArrayNumber(1)); } else if (pLensSeparation->GetArraySize() == 3) { SetLensSeparation(pLensSeparation->GetArrayNumber(2)); SetLensSeparationMin(pLensSeparation->GetArrayNumber(0)); SetLensSeparationMax(pLensSeparation->GetArrayNumber(1)); } /*以下是可选参数*/ if (pMobilePositon && pMobilePositon->Type == JSON_Array) {// 手机摆放位置 for (int i = 0; i < pMobilePositon->GetArraySize(); i++) { MobilePositionInfo *pNewItem = new MobilePositionInfo; if (pNewItem->FromJson(pMobilePositon->GetItemByIndex(i))) { m_MobilePositon.push_back(pNewItem); } else { delete pNewItem; } } } if (pOS && pOS->Type == JSON_String) { SetOS(pOS->GetStringValue()); } // if (pBrand && pBrand->Type == JSON_String) // { // SetBrand(pBrand->GetStringValue()); // } // if (pModel && pModel->Type == JSON_String) // { // SetModel(pModel->GetStringValue()); // } if (pMachineID && pMachineID->Type == JSON_Number) { SetMachineID(pMachineID->GetInt32Value()); } bRet = true; }// LensSeparation }// Display,GlassID }// Name , URL , ID return bRet; }