Php 从JSON提取数据并显示在SWAL警报中

Php 从JSON提取数据并显示在SWAL警报中,php,jquery,json,sweetalert,Php,Jquery,Json,Sweetalert,我在尝试将信息从Json显示到警报时遇到问题,这是我的代码 function check_values_chbx(){ var pre_insc = []; }).done(function(response){ for(i=0; i<response.length; i++){ pre_insc[i] = response[0]['personas'][i]['nam

我在尝试将信息从
Json
显示到警报时遇到问题,这是我的代码

 function check_values_chbx(){

        var pre_insc = [];
        }).done(function(response){   

            for(i=0; i<response.length; i++){
                           pre_insc[i] = response[0]['personas'][i]['name']+" "+response[0]['personas'][i]['ap_pat']+" "+response[0]['personas'][i]['ap_mat'];                            
                        }
                        alert(pre_insc[1]);
            swal({
              title: "Detalles de inscripcion",
              text: "Participantes que quedaran inscritos: \n\n"+pre_insc.join('\n')+"\n\nCategoria:",    
              buttons: true,
              dangerMode: false,
            }).then((willDelete) => {
              if (willDelete) {
                swal("Participantes registrados con exito, mucha suerte!", {
                  icon: "success",
                });
              }else {
                location.reload();
              }
            });


        });    
        }
我需要打印每个名称,如:

swal("name1\n"+name2\n"+etc").

如果有人能帮我,那会很有帮助的,祝您愉快。

如果找到
数组或
对象,您可以使用下面的脚本递归迭代
json
对象,直到找到给定属性的
文本,然后使用
\n
分隔符打印所有属性名称(如果属性名称为
name
),您可以在脚本文件中添加以下内容,并将收到的响应传递给脚本文件,并将返回的名称与
sweetAlert
一起使用,只需确保将响应传递给如下函数即可

names = jsonParser.getNames(response[0]);
在脚本中添加以下内容

var jsonParser = {
    isObject: function (property) {
        return property && {}.toString.call(property) === '[object Object]';
    },
    isArray: function (property) {
        return property && {}.toString.call(property) === '[object Array]';
    },
    getNames: function (errors) {
        var data = "";

        for (let message in errors) {
            var errorSet = errors;
            if (errorSet.hasOwnProperty(message)) {

                if (jsonParser.isArray(errorSet[message]) || jsonParser.isObject(
                        errorSet[message])) {
                    data += jsonParser.getNames(errors[message]);
                } else if (message == 'name') {
                    data += errorSet[message] + "\n";
                }

            }
        }
        return data;
    }
};
下面给出了从给定响应中读取名称的示例

var jsonParser={
isObject:函数(属性){
返回属性&&{}.toString.call(属性)=='[object]';
},
isArray:函数(属性){
返回属性&&{}.toString.call(属性)=='[对象数组]';
},
convertToString:函数(错误){
var数据=”;
for(让消息输入错误){
var errorSet=错误;
if(errorSet.hasOwnProperty(消息)){
if(jsonParser.isArray(errorSet[message])| | jsonParser.isObject(
错误集[消息]){
data+=jsonParser.convertToString(错误[消息]);
}else if(消息=='name'){
数据+=错误集[消息]+“\n”;
}
}
}
返回数据;
}
};
var响应=[{
“人物角色”:[{
“姓名”:“杰西卡”,
“ap_pat”:“BocaNegra”,
“ap_mat”:“加西亚”
},
{
“姓名”:“费尔南多”,
“ap_pat”:“Soto”,
“ap_mat”:“Olivas”
}
],
“事件”:[{
“名称”:“Carrera larga”
}],
“类别”:[{
“姓名”:“未成年人”
}]
}];
变量名称=“”;
name=jsonParser.convertToString(响应[0]);
console.log(名称)
var jsonParser = {
    isObject: function (property) {
        return property && {}.toString.call(property) === '[object Object]';
    },
    isArray: function (property) {
        return property && {}.toString.call(property) === '[object Array]';
    },
    getNames: function (errors) {
        var data = "";

        for (let message in errors) {
            var errorSet = errors;
            if (errorSet.hasOwnProperty(message)) {

                if (jsonParser.isArray(errorSet[message]) || jsonParser.isObject(
                        errorSet[message])) {
                    data += jsonParser.getNames(errors[message]);
                } else if (message == 'name') {
                    data += errorSet[message] + "\n";
                }

            }
        }
        return data;
    }
};