public function getJSONObject() { $obj = new JSONObject(); $obj->put("lat", $this->lat); $obj->put("lng", $this->lng); return $obj; }
/** * Converts the response in JSON format to the value object i.e Log * * @param json * - response in JSON format * * @return Log object filled with json data * */ function buildResponse($json) { $logObj = new Logging(); $msgList = array(); $logObj->setMessageList($msgList); $logObj->setStrResponse($json); $jsonObj = new JSONObject($json); $jsonObjApp42 = $jsonObj->__get("app42"); $jsonObjResponse = $jsonObjApp42->__get("response"); $logObj->setResponseSuccess($jsonObjResponse->__get("success")); $jsonObjLog = $jsonObjResponse->__get("logs"); if (!$jsonObjLog->has("log")) { return $logObj; } if ($jsonObjLog->__get("log") instanceof JSONObject) { // Only One attribute is there $jsonObjLogMessage = $jsonObjLog->__get("log"); $messageItem = new Message($logObj); $this->buildObjectFromJSONTree($messageItem, $jsonObjLogMessage); } else { // There is an Array of attribute $jsonObjMessageArray = $jsonObjLog->getJSONArray("log"); for ($i = 0; $i < count($jsonObjMessageArray); $i++) { // Get Individual Attribute Node and set it into Object $jsonObjLogMessage = $jsonObjMessageArray[$i]; $messageItem = new Message($logObj); $jsonObjLogMessage = new JSONObject($jsonObjLogMessage); $this->buildObjectFromJSONTree($messageItem, $jsonObjLogMessage); } } return $logObj; }
/** * Converts the response in JSON format to the value object i.e Recommender * * @param json * - response in JSON format * * @return Recommender object filled with json data * */ public function buildResponse($json) { $recommenderObj = new Recommender(); $recommendedItemList = array(); $recommenderObj->setRecommendedItemList($recommendedItemList); $recommenderObj->setStrResponse($json); $jsonObj = new JSONObject($json); $jsonObjApp42 = $jsonObj->__get("app42"); $jsonObjResponse = $jsonObjApp42->__get("response"); $recommenderObj->setResponseSuccess($jsonObjResponse->__get("success")); $jsonObjRecommender = $jsonObjResponse->__get("recommender"); $this->buildObjectFromJSONTree($recommenderObj, $jsonObjRecommender); if (!$jsonObjRecommender->has("recommended")) { return $recommenderObj; } if ($jsonObjRecommender->__get("recommended") instanceof JSONObject) { // Only One attribute is there $jsonObjRecommended = $jsonObjRecommender->__get("recommended"); $recomItem = new RecommendedItem($recommenderObj); $this->buildObjectFromJSONTree($recomItem, $jsonObjRecommended); } else { // There is an Array of attribute $jsonObjRecommenderArray = $jsonObjRecommender->getJSONArray("recommended"); for ($i = 0; $i < count($jsonObjRecommenderArray); $i++) { // Get Individual Attribute Node and set it into Object //$jsonObjRecommended = new JSONObject($jsonObjRecommenderArray[$i]); $jsonObjRecommended = $jsonObjRecommenderArray[$i]; $recomItem = new RecommendedItem($recommenderObj); $jsonObjRecommended = new JSONObject($jsonObjRecommended); $this->buildObjectFromJSONTree($recomItem, $jsonObjRecommended); } } return $recommenderObj; }
private function set($data) { foreach ($data as $key => $value) { if (is_array($value)) { $sub = new JSONObject(); $sub->set($value); $value = $sub; } $this->{$key} = $value; } }
/** * @param json * @return * @throws Exception */ public function getTotalRecords($json) { $totalRecords = -1; $jsonObj = new JSONObject($json); $jsonObjApp42 = $jsonObj->__get("app42"); $jsonObjResponse = $jsonObjApp42->__get("response"); // if(($jsonObjResponse != null) && ($jsonObjResponse->__get("totalRecords"))){ if ($jsonObjResponse != null) { $totalRecords = $jsonObjResponse->__get("totalRecords"); } return $totalRecords; }
/** * Converts the response in JSON format to the list of value objects i.e Geo * * @param json * - response in JSON format * * @return List of Geo Points object filled with json data * */ public function buildArrayResponse($json) { $geoObjList = array(); $jsonObj = new JSONObject($json); $jsonObjApp42 = $jsonObj->__get("app42"); $jsonObjResponse = $jsonObjApp42->__get("response"); $jsonObjGeoStorage = $jsonObjResponse->__get("geo"); if ($jsonObjGeoStorage->__get("storage") instanceof JSONObject) { //Single Item $jsonObjGeoStorage = $jsonObjGeoStorage->__get("storage"); $geoObj = new Geo(); $pointList = array(); $geoObj->setPointList($pointList); $geoObj->setStrResponse($json); $geoObj->setResponseSuccess($jsonObjResponse->__get("success")); $this->buildObjectFromJSONTree($geoObj, $jsonObjGeoStorage); array_push($geoObjList, $geoObj); if ($jsonObjGeoStorage->has("points")) { $this->buildInternalObj($geoObj, $jsonObjGeoStorage); } } else { //Multiple Item $jsonStorageArray = $jsonObjGeoStorage->getJSONArray("storage"); for ($i = 0; $i < count($jsonStorageArray); $i++) { $jsonObjStorage = $jsonStorageArray[$i]; $geoObj = new Geo(); $pointList = array(); $geoObj->setPointList($pointList); $geoObj->setStrResponse($json); $geoObj->setResponseSuccess($jsonObjResponse->__get("success")); $jsonObjStorage = new JSONObject($jsonObjStorage); $this->buildObjectFromJSONTree($geoObj, $jsonObjStorage); array_push($geoObjList, $geoObj); if ($jsonObjStorage->has("points")) { $this->buildInternalObj($geoObj, $jsonObjStorage); } } } return $geoObjList; }
/** * Converts the response in JSON format to the value object i.e Session * * @param json * - response in JSON format * * @return Session object filled with json data * */ public function buildResponse($json) { $sessionObj = new Session(); $attributeList = array(); $sessionObj->setAttributeList($attributeList); $sessionObj->setStrResponse($json); $jsonObj = new JSONObject($json); $jsonObjApp42 = $jsonObj->__get("app42"); $jsonObjResponse = $jsonObjApp42->__get("response"); $sessionObj->setResponseSuccess($jsonObjResponse->__get("success")); $jsonObjSession = $jsonObjResponse->__get("session"); $this->buildObjectFromJSONTree($sessionObj, $jsonObjSession); if (!$jsonObjSession->has("attributes")) { return $sessionObj; } $jsonObjAttributes = $jsonObjSession->__get("attributes"); if (!$jsonObjAttributes->has("attribute")) { return $sessionObj; } if ($jsonObjAttributes->__get("attribute") instanceof JSONObject) { // Only One attribute is there $jsonObjAttribute = $jsonObjAttributes->__get("attribute"); $attribute = new Attribute($sessionObj); $this->buildObjectFromJSONTree($attribute, $jsonObjAttribute); } else { // There is an Array of attribute $jsonObjAttributeArray = $jsonObjAttributes->getJSONArray("attribute"); for ($i = 0; $i < count($jsonObjAttributeArray); $i++) { //Get Individual Attribute Node and set it into Object $jsonObjAttribute = $jsonObjAttributeArray[$i]; $attribute = new Attribute($sessionObj); $jsonObjAttribute = new JSONObject($jsonObjAttribute); $this->buildObjectFromJSONTree($attribute, $jsonObjAttribute); } } return $sessionObj; }
/** * Converts the response in JSON format to the value object i.e Email * * @params json * - response in JSON format * * @return Email object filled with json data * */ function buildResponse($json) { $emailObj = new Email(); $configList = array(); $emailObj->setConfigList($configList); $emailObj->setStrResponse($json); $jsonObj = new JSONObject($json); $jsonObjApp42 = $jsonObj->__get("app42"); $jsonObjResponse = $jsonObjApp42->__get("response"); $emailObj->setResponseSuccess($jsonObjResponse->__get("success")); $jsonObjEmail = $jsonObjResponse->__get("email"); $this->buildObjectFromJSONTree($emailObj, $jsonObjEmail); if (!$jsonObjEmail->has("configurations")) { return $emailObj; } $jsonEmailConfig = $jsonObjEmail->__get("configurations"); if (!$jsonEmailConfig->has("config")) { return $emailObj; } if ($jsonEmailConfig->__get("config") instanceof JSONObject) { // Only One attribute is there $jsonObjConfig = $jsonEmailConfig->__get("config"); $configItem = new Configuration($emailObj); $this->buildObjectFromJSONTree($configItem, $jsonObjConfig); } else { // There is an Array of attribute $jsonObjConfigArray = $jsonEmailConfig->getJSONArray("config"); for ($i = 0; $i < count($jsonObjConfigArray); $i++) { // Get Individual Attribute Node and set it into Object $jsonObjConfigs = $jsonObjConfigArray[$i]; $configItem = new Configuration($emailObj); $jsonObjConfig = new JSONObject($jsonObjConfigs); $this->buildObjectFromJSONTree($configItem, $jsonObjConfig); } } return $emailObj; }
/** * Builds the Json Document for the storage w.r.t their docId * * @param document * - document for storage * @param jsonObjDoc * - jsonDoc object for storage * */ function buildJsonDocument($document, $jsonObjDoc) { $jsonObjDoc = new JSONObject($jsonObjDoc); if ($jsonObjDoc->has("loc") && $jsonObjDoc->__get("loc") != null) { $geoArray = $jsonObjDoc->getJSONArray("loc"); for ($i = 0; $i < count($geoArray); $i++) { if (count($geoArray) == 2) { $geoTag = new GeoTag(); $geoTag->setLat($geoArray[0]); $geoTag->setLng($geoArray[1]); $document->setLocation($geoTag); $jsonObjDoc->remove("loc"); } } } if ($jsonObjDoc->has("_id") && $jsonObjDoc->__get("_id") != null) { $idObj = $jsonObjDoc->__get("_id"); $oIdObj = $idObj->__get("\$oid"); $document->setDocId($oIdObj); $jsonObjDoc->remove("_id"); } if ($jsonObjDoc->has("_\$updatedAt") && $jsonObjDoc->__get("_\$updatedAt") != null) { $updatedObj = $jsonObjDoc->__get("_\$updatedAt"); $document->setUpdatedAt($updatedObj); $jsonObjDoc->remove("_\$updatedAt"); } if ($jsonObjDoc->has("_\$createdAt") && $jsonObjDoc->__get("_\$createdAt") != null) { $createdAtObj = $jsonObjDoc->__get("_\$createdAt"); $document->setCreatedAt($createdAtObj); $jsonObjDoc->remove("_\$createdAt"); } if ($jsonObjDoc->has("_\$event") && $jsonObjDoc->__get("_\$event") != null) { $eventObj = $jsonObjDoc->__get("_\$event"); $document->setEvent($eventObj); $jsonObjDoc->remove("_\$event"); } if ($jsonObjDoc->has("_\$owner") && $jsonObjDoc->__get("_\$owner") != null) { $idObj = $jsonObjDoc->__get("_\$owner"); $ownerObj = $idObj->__get("owner"); $document->setOwner($ownerObj); $jsonObjDoc->remove("_\$owner"); } $document->setJsonDoc($jsonObjDoc); }
function buildArrayResponse($json) { $pushListObject = array(); $channelList = array(); $jsonObj = new JSONObject($json); $jsonObjApp42 = $jsonObj->__get("app42"); $jsonObjResponse = $jsonObjApp42->__get("response"); $jsonObjPush = $jsonObjResponse->__get("push"); if ($jsonObjPush instanceof JSONObject) { $pushObj = new PushNotification(); $pushObj->setChannelList($channelList); $this->buildObjectFromJSONTree($pushObj, $jsonObjPush); if ($jsonObjPush->has("channels")) { $jsonPushChannels = $jsonObjPush->__get("channels"); if ($jsonPushChannels->__get("channel") instanceof JSONObject) { // Only One attribute is there $jsonObjchannel = $jsonPushChannels->__get("channel"); $channelList1 = new Channel($pushObj); $this->buildObjectFromJSONTree($channelList1, $jsonObjchannel); } else { // There is an Array of attribute $jsonObjChanelArray = $jsonPushChannels->getJSONArray("channel"); for ($i = 0; $i < count($jsonObjChanelArray); $i++) { // Get Individual Attribute Node and set it into Object $jsonObjChannelLi = $jsonObjChanelArray[$i]; $channelListObj = new Channel($pushObj); $jsonObjChann = new JSONObject($jsonObjChannelLi); $this->buildObjectFromJSONTree($channelListObj, $jsonObjChann); } } } $pushObj->setStrResponse($json); $pushObj->setResponseSuccess($this->isRespponseSuccess($json)); array_push($pushListObject, $pushObj); } else { $pushJSONArray = $jsonObjResponse->getJSONArray("push"); for ($i = 0; $i < count($pushJSONArray); $i++) { $pushObject = new PushNotification(); $pushObject->setChannelList($channelList); $pushJSONObj = $pushJSONArray[$i]; $pushJSONObject = new JSONObject($pushJSONObj); $this->buildObjectFromJSONTree($pushObject, $pushJSONObject); if ($pushJSONObject->has("channels")) { $jsonPushChannelss = $pushJSONObject->__get("channels"); if ($jsonPushChannelss->has("channel")) { if ($jsonPushChannelss->__get("channel") instanceof JSONObject) { // Only One attribute is there $jsonObjchannelA = $jsonPushChannelss->__get("channel"); $channelListObject = new Channel($pushObject); $this->buildObjectFromJSONTree($channelListObject, $jsonObjchannelA); } else { // There is an Array of attribute $jsonObjChanelArray = $jsonPushChannelss->getJSONArray("channel"); for ($i = 0; $i < count($jsonObjChanelArray); $i++) { // Get Individual Attribute Node and set it into Object $jsonObjChannelList = $jsonObjChanelArray[$i]; $channelList2 = new Channel($pushObject); $jsonObjChannel = new JSONObject($jsonObjChannelList); $this->buildObjectFromJSONTree($channelList2, $jsonObjChannel); // $pushObj->setChannelList($channelList); } } } } $pushObject->setStrResponse($json); $pushObject->setResponseSuccess($this->isRespponseSuccess($json)); array_push($pushListObject, $pushObject); } } return $pushListObject; }
function buildJsonFacebookProfileLink($me, $friendJSONObj) { $jsonObjMe = new JSONObject($friendJSONObj); if ($jsonObjMe->has("id") && $jsonObjMe->__get("id") != null) { $me->setId($jsonObjMe->__get("id")); $me->setName($jsonObjMe->__get("name")); $me->setPicture($jsonObjMe->__get("picture")); $me->setFirstName($jsonObjMe->__get("firstName")); $me->setLastName($jsonObjMe->__get("lastName")); $me->setGender($jsonObjMe->__get("gender")); $me->setLink($jsonObjMe->__get("link")); $me->setLocale($jsonObjMe->__get("locale")); $me->setUserName($jsonObjMe->__get("username")); } }
function deleteDocumentsByKeyValue($dbName, $collectionName, $key, $value) { Util::throwExceptionIfNullOrBlank($dbName, "DataBase Name"); Util::throwExceptionIfNullOrBlank($collectionName, "Collection Name"); Util::throwExceptionIfNullOrBlank($key, "Key"); Util::throwExceptionIfNullOrBlank($value, "Value"); $encodedDbName = Util::encodeParams($dbName); $encodedCollectionName = Util::encodeParams($collectionName); $encodedKey = Util::encodeParams($key); $responseObj = new App42Response(); $objUtil = new Util($this->apiKey, $this->secretKey); try { $params = null; $headerParams = array(); $queryParams = array(); $signParams = $this->populateSignParams(); $metaHeaders = $this->populateMetaHeaderParams(); $headerParams = array_merge($signParams, $metaHeaders); $json = new JSONObject(); $json->put("key", $value); $signParams['value'] = $json; $params = array_merge($queryParams, $signParams); $signParams['dbName'] = $dbName; $signParams['collectionName'] = $collectionName; $signParams['key'] = $key; $signature = urlencode($objUtil->sign($signParams)); //die(); $headerParams['signature'] = $signature; $contentType = $this->content_type; $accept = $this->accept; $baseURL = $this->url; $baseURL = $baseURL . "/deletebykey" . "/dbName" . "/" . $encodedDbName . "/collectionName" . "/" . $encodedCollectionName . "/" . $encodedKey; $response = RestClient::delete($baseURL, $params, null, null, $contentType, $accept, $headerParams); $responseObj->setStrResponse($response->getResponse()); $responseObj->setResponseSuccess(true); } catch (App42Exception $e) { throw $e; } catch (Exception $e) { throw new App42Exception($e); } return $responseObj; }
function buildJsonFacebookProfile($me, $friendJSONObj) { $jsonObjMe = new JSONObject($friendJSONObj); if ($jsonObjMe->has("id") && $jsonObjMe->__get("id") != null) { $me->setId($jsonObjMe->__get("id")); $me->setName($jsonObjMe->__get("name")); $me->setPicture($jsonObjMe->__get("picture")); } }
<?php error_reporting(E_ALL); ini_set('display_errors', true); require 'JSONObject.php'; $jo = new JSONObject(); $json_str = '{ "userid": "zhangsan", "name": "张三", "tel" : "010-123333", "workPlace" :"", "remark" : "", "mobile" : "13800000000", "email" : "*****@*****.**", "active" : true, "orderInDepts" : "{1:10, 2:20}", "isAdmin" : false, "isBoss" : false, "dingId" : "WsUDaq7DCVIHc6z1GAsYDSA", "isLeaderInDepts" : "{1:true, 2:false}", "isHide" : false, "department": [1, 2], "position": "工程师", "avatar": "dingtalk.com/abc.jpg", "jobnumber": "111111", "extattr": { "爱好":"旅游", "年龄":"24" } }'; echo $jo->toClass('User', json_decode($json_str, true));
public function getJSONObject() { $obj = new JSONObject(); $obj->put("latitude", $this->latitude); $obj->put("longitude", $this->longitude); $obj->put("markerName", $this->marker); return $obj; }
private function getJsonObj() { $aclArray = array(); $acl = new ACL($user, $permission); foreach ($this->{$acl} as $aclList) { $newJSON = new JSONObject(); $user = $acl->getUser(); $permission = $acl->getPermission(); $newJSON->put($user, $permission); array_push($aclArray, $newJSON); } return $aclArray; }