2017-09-01 27 views
1

私のWSDLファイル: -php soap Webサービスのjson応答からバックスラッシュを削除するには?

<?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); 


?> 

とURLの応答: - http://meter.digireach.com/RnBCode/presentstatus.php?rnbcode=DR00098EM

と出力は次のようです: -

"{\" srno \ ":\" 1 \ "、\" tr_date \ ":\" 2017-08-22 11:53:33 \ "、\" did \ ":\" DR00098EM \ \ "p1 \"、\ "p2 \"、\ "0 \"、\ "p3 \"、\ "0 \"、\ "p4 \ "p \ "p6 \"、\ "p7 \"、\ "60 \"、\ "p8 \":\ "40 \"、\ "p9 \ \ "p11 \"、\ "p12 \"、\ "0 \"、\ "p13 \": \ "p15 \"、\ "p16 \"、\ "p16 \"、\ "p17 \":\ "p14 \ \ "p1 \"、\ "p19 \"、\ "1 \"、\ "p20 \"、\ "1 \"、\ "tno \":\ " "、" "ser_date":\ "2017-08-22 11:54:12 \"} "

このように、このjsonレスポンスからバックスラッシュ()を削除したいと考えています。

答えて

1

有効なJSONヘッダーを設定していないため、APIレスポンスはJSONではありません。

解決策1: JSON出力の前に有効なContent-Typeヘッダーを設定する必要があります。次のように:

header('Content-Type: application/json'); 
echo json_encode($result, JSON_NUMERIC_CHECK); 

や、解決方法2: は......二回

+1

json_decode(json_decode($json))はありがとう、あなたの出力をデコード –

関連する問題