xml和json格式輸出

2022-09-15 03:39:13 字數 1476 閱讀 6883

<?php

class response

$type = isset($_get['format']) ? $_get['format'] : self::json;

$result = array(

'code' => $code,

'message' => $message,

'data' => $data

);if($type == 'json')elseif ($type == 'array') elseif ($type == 'xml') else}/*

* 按json方式輸出通訊資料

* @param integer $code 狀態碼

* @param string $message 提示資訊

* @param array $data 資料

* return string

*/public static function json($code,$message='',$data=array())

$result = array(

'code' => $code,

'message' => $message,

'data' => $data

);echo json_encode($result);

exit;}/*

* 按xml方式輸出通訊資料

* @param integer $code 狀態碼

* @param string $message 提示資訊

* @param array $data 資料

* return string

*/public static function xmlencode($code,$message='',$data=array())

$result = array(

'code' => $code,

'message' => $message,

'data' => $data,

);//指定頁面顯示型別

header("content-type:text/xml");

$xml = "<?xml version='1.0' encoding='utf-8' ?>";

$xml .= "\n";

//拼接xml資料格式

$xml .= self::xmltoencode($result);

$xml .= "";

echo $xml;

exit;

}public static function xmltoencode($data)'";

$key = "item";

}$xml .= "<>";

$xml .= is_array($value) ? self::xmltoencode($value) : $value;

$xml .= "\n";

}return $xml;}}

?>

來自為知筆記(wiz)

xml和json互轉的格式,結構

xml bpm transition class dealevent 測試3 01 2noticecheck y emailcheck y repeatcheck y remindercheck y readonlycheck y tasktime 1 timeunits 分鐘 outdeal 郵件...

xml和json互轉的格式,結構

xml bpm transition class dealevent 測試3 01 2noticecheck y emailcheck y repeatcheck y remindercheck y readonlycheck y tasktime 1 timeunits 分鐘 outdeal 郵件...

資料互動格式之xml和json

計算機中用於資料傳輸的通訊語言 1.xml 一種可擴充套件的標記語言,可以自定義標籤的資料傳輸格式。2.json js物件簡譜,一種輕量級的資料互動格式。為什麼要學習資料傳輸語言 因為在實習開發中,需要獲取資料,不同語言支援的資料通訊語言也不同,為了方便開發,需要統一資料互動的語言,因此學習xml和...