-2

I am working with WSDL for my web services. So, I created a WSDL page and add a function. This function is, connect my table and return JSON value. When I call this function other PHP page, I take successful my values.

[{"ID":"1","Number":"1"}]

But, when I call this function in my WSDL page, I get it:

[{"ID":"1","Number":"1","}]

And this my function in WSDL:

public function A($a1,$a2,$a3,$o1) 
    {
    include "../conf/database.php";
    $SQL = "SELECT * FROM table_users";  
    $SQLResult=mysqli_query($conn,$SQL);
    while($row=mysqli_fetch_assoc($SQLResult))
    {
        $JSON[] = $row;
    }
    return json_encode($JSON,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_HEX_QUOT | JSON_HEX_APOS);
    }

I found a lot of solutions, but it didn't work. I try preg_replace, replace but I can't. How I solve this problem?

My WSDL PHP Page:

<?php
require_once "lib/nusoap.php";
$JSON= array();

    public function A($a1,$a2,$a3,$o1) 
    {
    include "../conf/database.php";
    $SQL = "SELECT * FROM table_users";  
    $SQLResult=mysqli_query($conn,$SQL);
    while($row=mysqli_fetch_assoc($SQLResult))
    {
        $JSON[] = $row;
    }
    return json_encode($JSON,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_HEX_QUOT | JSON_HEX_APOS);
    }

$server = new soap_server();
$server->configureWSDL("TryFunc", "MyURL");
  $server->wsdl->addComplexType('A',
    'complexType',
    'struct',
    'all',
    '',
    array(
            'a1' => array('name' => 'a1', 'type' => 'xsd:string'),
            'a2' => array('name' => 'a2', 'type' => 'xsd:string'),
            'a3' => array('name' => 'a3', 'type' => 'xsd:int'),
            'o1' => array('name' => 'o1', 'type' => 'xsd:string'),
    )
);
$server->register('A',                   
  array('a1' => 'xsd:string', 'a2' => "xsd:string",'a3' => "xsd:int",'o1' => "xsd:string"),      
   array("return" => "xsd:string"),
    "",
    "",
    "rcp",
    "encoded",
    "document");

@$server->service(file_get_contents("php://input"));
AlpYuktug
  • 178
  • 1
  • 2
  • 13

1 Answers1

-1

Dead simple: JSON isn't allowed to use single quotes.

It's actually counter-intuitive at least if you use PHP as double quotes will output a variable and single quotes will output the literal variable name itself. Why JSON strictly prefers double quotes is not something I personally know though I do personally consider it a flaw. I was not able to find out why in searches on Duck Duck Go and Google. You could research the original author Douglas Crockford and see what programming language(s) he programmed as it may be the reverse of PHP, an oversight, zealous belief, etc.

John
  • 1
  • 13
  • 98
  • 177