{ $this->innerobject = new object2(); } } class object2 { var $firstattr = 'firstvalue'; var $secondattr = 'secondvalue'; } //---- variables --------------------------------------------------------------- $JSON = new JSON(); $object1 = new object1(); $JSON2 = new Services_JSON(); $submitted = false; //---- logic ------------------------------------------------------------------- $origjsonstring = $JSON->stringify($object1); $newjsonstring = $JSON2->encode($object1); $origjson = $_REQUEST["origjson"]; if (!empty($origjson)) { $origjsonprintr = $JSON->parse(stripslashes($origjson)); $submitted = true; } else { $origjsonprintr = "Not submitted"; } $newjson = $_REQUEST["newjson"]; if (!empty($newjson)) { $newjsonprintr = $JSON2->decode(stripslashes($newjson)); } else { $newjsonprintr = "Not submitted"; } //---- content -----------------------------------------------------------------
/** * Converts Request to Curl console command. * * @param Request $request * * @return string */ public static function convertRequestToCurlCommand(Request $request) { $message = 'curl -X' . strtoupper($request->getMethod()) . ' '; $message .= '\'http://' . $request->getConnection()->getHost() . ':' . $request->getConnection()->getPort() . '/'; $message .= $request->getPath(); $query = $request->getQuery(); if (!empty($query)) { $message .= '?' . http_build_query($query); } $message .= '\''; $data = $request->getData(); if (!empty($data)) { $message .= ' -d \'' . JSON::stringify($data) . '\''; } return $message; }
{ return $this->name; } } //---- variables --------------------------------------------------------------- $JSON = new JSON(); $myObj = new MyObj(); //---- logic ------------------------------------------------------------------- /* initialize object */ $myObj->setId('�l' . chr(18) . "ie\nn"); $myObj->setName('objectName'); array_push($myObj->attribs, '�first'); array_push($myObj->attribs, 'second'); array_push($myObj->attribs, 3); /* create JSON representation */ $jsonStr = $JSON->stringify($myObj); //---- clean-up ---------------------------------------------------------------- //---- content ----------------------------------------------------------------- ?> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>JSON parser test</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript" src="json.js"></script> <script type="text/javascript"> JSON.arrayObj = new Array(); JSON.parse2 = function (text) { var p = /^\s*(([,:{}\[\]])|"(\\.|[^\x00-\x1f"\\])*"|-?\d+(\.\d*)?([eE][+-]?\d+)?|true|false|null|\/\*Array\*\/)\s*/, token, operator;