现在我告诉你一切: 第1步
var team = '[';
var filas=$("#players").find("tbody").find("tr").not(".hidden");
for(i=0;i<$(filas).length;i++)
{
team+='{"type_player": "' + $(filas).eq(i).find("td.dato").eq(0).html() + '" ,"mo": ' + parseInt($(filas).eq(i).find("td.dato").eq(1).html()) + ', "st": ' + parseInt($(filas).eq(i).find("td.dato").eq(2).html()) + ', "de": ' + parseInt($(filas).eq(i).find("td.dato").eq(3).html()) + ', "ar": ' + parseInt($(filas).eq(i).find("td.dato").eq(4).html()) + ', "N": "' + $(filas).eq(i).find("td.dato").eq(6).html() + '" , "D": "' + $(filas).eq(i).find("td.dato").eq(7).html() + '" , "price": ' + parseInt($(filas).eq(i).find("td.dato").eq(8).html()) + ', "habs": ' + $(filas).eq(i).find("input.p_habs").val() + ', "max_number": '+ $(filas).eq(i).find("td.dato").eq(9).html() + ' }';
if((i+1)<$(filas).length)
{
team+=", ";
}
}
team+="]";
第2步
$("#lista_Players").val(JSON.stringify(team));
其中lista_Players是表单中的隐藏输入
第3步
<form action='crear_raza.php' method="post">
第4步
$play=$_POST['players'];
第5步
$players=json_decode($play, true);
第6步
我print_r($玩家)显示:
[{"type_player": "Putrefactos" ,"mo": 5, "st": 3, "de": 3, "ar": 8, "N": "GM" , "D": "AFP" , "price": 40000, "habs": [22,60], "max_number": 16 }, {"type_player": "Pestigors" ,"mo": 6, "st": 3, "de": 3, "ar": 8, "N": "FGM" , "D": "AP" , "price": 80000, "habs": [20,60,64], "max_number": 4 }, {"type_player": "Guerreros de Nurgle" ,"mo": 4, "st": 4, "de": 2, "ar": 9, "N": "FGM" , "D": "AP" , "price": 110000, "habs": [5,57,60,64], "max_number": 4 }, {"type_player": "Bestia de Nurgle" ,"mo": 4, "st": 5, "de": 1, "ar": 9, "N": "F" , "D": "AGMP" , "price": 140000, "habs": [5,34,57,60,62,64,71,72], "max_number": 1 }, {"type_player": "erger" ,"mo": 3, "st": 3, "de": 3, "ar": 3, "N": "A" , "D": "P" , "price": 2345324, "habs": [1], "max_number": 4 }]
JSON格式化程序正好说:VALID JSON(RFC 4627)
第7步
echo $players[0]["mo"];
它让我:[
echo $players[0]["type_player"];
它什么都没有给我回复
任何想法????
答案 0 :(得分:0)
你应该知道JSON意味着 J ava S crpt O bject N orotation和构建字符串是没有意义的。您可以创建简单对象并将变量放入其中。 例如:
var players = [
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter","lastName": "Jones"}
];