【发布时间】:2014-04-29 09:40:02
【问题描述】:
您好,我的 Web 应用程序有问题。在一个 html 页面中,我有两个以上的 json(这是 php 页面的结果),并且使用 jquery 函数我必须解析它们。 问题是,如果页面中只有一个用于解析的 json,则没有问题,但如果有两个或更多 json,则它不起作用。哪个是问题? 有人可以帮助我吗? 这是 json 的两个例子:
{"Nr SAT":"SAT000000002574","Tipo Servizio":"GR","Stato":"ciao","Attributo":"APERTURA SAT SU IMEI DUPLICATO","Marca":"LG","Modello":"U830","Modello Guasto":"353142010979931"}
{"Nr SAT":"SAT000000002574","Tipo Servizio":"Vedi anche me","Stato":"ahhhhhhhhhhhhh","Attributo":"APERTURA SAT SU IMEI DUPLICATO","Marca":"LG","Modello":"U830","Modello Guasto":"353142010979931"}
这些是我用于解析的 jquery 函数:
<script>
$.getJSON('http://sath3g.altervista.org/index.php', { get_param: 'value' }, function(data) {
$('body').append($('<p>').html('Tipo di Servizio: '+ data["Tipo Servizio"]));
});
$.getJSON('http://sath3g.altervista.org/index.php', { get_param: 'value' }, function(data) {
$('body').append($('<p>').html('Stato: '+ data["Stato"]));
});
$.getJSON('http://sath3g.altervista.org/index.php', { get_param: 'value' }, function(data) {
$('body').append($('<p>').html('Nr SAT: '+ data["Nr SAT"]));
});
$.getJSON('http://sath3g.altervista.org/index.php', { get_param: 'value' }, function(data) {
$('body').append($('<p>').html('Attributo: '+ data["Attributo"]));
});
$.getJSON('http://sath3g.altervista.org/index.php', { get_param: 'value' }, function(data) {
$('body').append($('<p>').html('Marca: '+ data["Marca"]));
});
</script>
这是生成 json 的 php。 如果在控件“if ($line_of_text[0] == "SAT000000002574")”中我有多个结果,我可以通过哪种方式生成正确格式的 json?
<?php
// Sopprimo gli errori del php
error_reporting(0);
// Includo la libreria
require_once 'excel_reader2.php';
//Recupero il valore del parametro "nome"
$file_handle = fopen("leggimi2.csv", "r");
while (!feof($file_handle) ) {
$line_of_text = fgetcsv($file_handle, 1024);
if ($line_of_text[0] == "SAT000000002574")
{
//print $line_of_text[0]." ".$line_of_text[1]." ".$line_of_text[2]." ".$line_of_text[3]." ".$line_of_text[4]." ".$line_of_text[5]." ".$line_of_text[6]." ".$line_of_text[7];
$arr = array('Nr SAT' => $line_of_text[0], 'Tipo Servizio' => $line_of_text[1], 'Stato' => $line_of_text[2], 'Attributo' => $line_of_text[3], 'Marca' => $line_of_text[4], 'Modello' => $line_of_text[5],
'Modello Guasto' => $line_of_text[6]);
echo json_encode($arr);
}
}
【问题讨论】: