简体   繁体   English

读取JSON格式

[英]Read JSON Format

I've created a line of code that function to read data from SOAP service. 我创建了一行代码,用于从SOAP服务读取数据。 But I have a little problem. 但是我有一点问题。 I'm using JSONP Lib in this task but has not produced results. 我在此任务中使用JSONP Lib,但未产生结果。 I tried the same with less code to read the output of a database query and the results were successful. 我用更少的代码尝试了相同的操作,以读取数据库查询的输出,并且结果成功。 Is there a difference between these two methods? 这两种方法之间有区别吗? The first one I made ​​the PHP code to transfer the array into the form of json : 我编写的第一个PHP代码将数组转换为json形式:

<?php
error_reporting(0);
header('content-type:application/json;charset=UTF-8');
date_default_timezone_set("Asia/Jakarta");
require_once('lib/nusoap.php');

$Param1 = "bertho_joris@yahoo.co.id";
$Param2 = "12345";

$client = new nusoap_client('http://vcare.telkomvision.net.id/services/VcareServices.php');
$ReadSOAP = $client->call('validateLogin', array('EMAIL' => $Param1, 'PASSWORD' => md5($Param2)));

echo '{"items":['. json_encode($ReadSOAP) .']}';
?>

And the data produced by the above code is : 上面的代码产生的数据是:

{
"items": [
    {
        "NE": "42616324457",
        "EMAIL": "bertho_joris@yahoo.co.id",
        "TIPE": "POSTPAID",
        "NAMA": "ALBERTHO MALAQUENA JORIS/NPK:120488047",
        "TELP": "081310117966 / 087878837451",
        "DN": "127225148174",
        "STATUS_LOGIN": "1",
        "DESC_LOGIN": "Valid"
      }
   ]
}

I use the library below to process the output data to be read later in my application : JSONP Library 我使用下面的库来处理输出数据,以便稍后在我的应用程序中读取: JSONP库

JSONP.get( 'MyURL.php', {Email:'MyEmail', Password:'MyPass'}, function(data){
    for ( var i = 0; i < response.length; ++i ) {
          str = response[i].ne;
          str2 = response[i].email;
          str3 = response[i].tipe;
          str4 = response[i].nama;
          str5 = response[i].telp;
          str6 = response[i].dn;
          str7 = response[i].desc_login;
    }
});

But the result I get is : My application can not read data output directly from the SOAP above . 但是我得到的结果是: 我的应用程序无法直接从上面的SOAP读取数据输出 I am confused why be like that. 我很困惑为什么会这样。 And I think JSON format is correct. 而且我认为JSON格式是正确的。

Then I tried to read the data directly from the database. 然后,我尝试直接从数据库中读取数据。 This database is a sample, and I accidentally made ​​the same data with the output of the SOAP reading process above. 这个数据库是一个示例,我不小心将上面的SOAP读取过程的输出与相同的数据制成了。

And the result, I successfully get the data. 结果,我成功获取了数据。

I include two links that I use to do the reading. 我包括两个用于阅读的链接。

  1. This link is the php file that processes the SOAP directly from the server and the output is JSON : Failed to Reading 此链接是直接从服务器处理SOAP的php文件,输出为JSON: 读取失败

  2. This is the direct link to the database with a dummy database. 这是使用虚拟数据库到数据库的直接链接。 JSON output. JSON输出。 And I succeed using this second method : Success to Reading 我成功使用了第二种方法: 阅读成功

Please help me resolve my problem was. 请帮我解决我的问题了。 The point I want to read the data directly from the process using the SOAP form that outputs JSON. 我想使用输出JSON的SOAP形式直接从流程中读取数据。 as I have described as a failure. 正如我所说的失败。

Thank you 谢谢

Try this: 尝试这个:

JSONP.get( 'MyURL.php', {Email:'MyEmail', Password:'MyPass'}, function(data){
    for (var i = 0; i < response.length; i++) 
    {
        str  = response[i].NE;
        str2 = response[i].EMAIL;
        str3 = response[i].TIPE;
        str4 = response[i].NAMA;
        str5 = response[i].TELP;
        str6 = response[i].DN;
        str7 = response[i].DESC_LOGIN;
    }
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM