我的wsdl文件: -
<?php
/**
@Description: Book Information Server Side Web Service:
This Sctript creates a web service using NuSOAP php library.
fetchBookData function accepts ISBN and sends back book information.
@Author: http://programmerblog.net/
@Website: http://programmerblog.net/
*/
require_once('dbconn.php');
require_once('lib/nusoap.php');
$server = new nusoap_server();
/* Fetch 1 book data */
function presentStatusPull($rnbcode){
global $dbconn;
$sql = "SELECT * FROM rnb_gpl_data where did = :rnbcode";
// prepare sql and bind parameters
$stmt = $dbconn->prepare($sql);
$stmt->bindParam(":rnbcode", $rnbcode);
// insert a row
$stmt->execute();
$data = $stmt->fetch(PDO::FETCH_ASSOC);
return json_encode($data);
$dbconn = null;
}
$server->configureWSDL('index', 'urn:index');
$server->register('presentStatusPull',
array('rnbcode' => 'xsd:string'),
array('data' => 'xsd:string'),
'urn:index',
'urn:index#presentStatusPull'
);
$server->service(file_get_contents("php://input"));
?>
然后我的php文件调用wsdl服务器: -
<?php
require_once('lib/nusoap.php');
$result = array();
$wsdl = "http://meter.digireach.com/RnBCode/index.php?wsdl";
$rnbcode = $_GET['rnbcode'];
//create client object
$client = new nusoap_client($wsdl, true);
$result = $client->call('presentStatusPull', array($rnbcode));
// $result = json_decode($result);
// echo json_encode($result);
echo json_encode($result, JSON_NUMERIC_CHECK);
?>
以及网址的回复: - http://meter.digireach.com/RnBCode/presentstatus.php?rnbcode=DR00098EM
和输出是这样的: -
&#34; {\&#34; srno \&#34;:\&#34; 1 \&#34; \&#34; tr_date \&#34;:\&#34; 2017年-08-22 11:53:33 \&#34;,\&#34;做了\&#34;:\&#34; DR00098EM \&#34;,&#34; p1 \&#34; :\&#34; 455 \&#34; \&#34; P2 \&#34;:\&#34; 0 \&#34; \&#34; P3 \&#34;:\ &#34; 0 \&#34; \&#34; P4 \&#34;:\&#34; 48 \&#34; \&#34; P5 \&#34;:\&# 34; 0 \&#34; \&#34; P6 \&#34;:\&#34; 0 \&#34; \&#34; P7 \&#34;:\&#34; 60 \&#34; \&#34; P8 \&#34;:\&#34; 40 \&#34; \&#34; P9 \&#34;:\&#34; 0 \ &#34; \&#34; P10 \&#34;:\&#34; 0 \&#34; \&#34; P11 \&#34;:\&#34; 5 \&# 34; \&#34; P12 \&#34;:\&#34; 0 \&#34; \&#34; P13 \&#34;:\&#34; 0 \&#34; ,\&#34; P14 \&#34;:\&#34; 1103 \&#34; \&#34; P15 \&#34;:\&#34; 36170 \&#34; \ &#34; P16 \&#34;:\&#34; 511046 \&#34; \&#34; P17 \&#34;:\&#34; 0 \&#34; \&# 34; P18 \&#34;:\&#34; 1 \&#34; \&#34; P19 \&#34;:\&#34; 1 \&#34; \&#34; P20 \&#34;:\&#34; 1 \&#34; \&#34; TNO \&#34;:\&#34;理想\&#34; \&#34; ser_date \ &#34;:\&#34; 2017-08-22 11:54:12 \&#34;}&#34;
所以,我想从这个json响应中删除反斜杠()。
答案 0 :(得分:1)
您没有设置有效的JSON标头,这就是您的API响应是字符串而不是JSON的原因。
解决方案1: 您应该在JSON输出之前设置有效的Content-Type标头。如下:
header('Content-Type: application/json');
echo json_encode($result, JSON_NUMERIC_CHECK);
或,解决方案2:
将输出解码两次json_decode(json_decode($json))