1
正如标题所说,我得到了一个Xml文件并读取了php中的值并将它们保存在一个数组中。我的数组在PHP中完美工作。从XML到PHP到数组到JSON对象
我可以返回只是把它们从数组我的价值观逐一:
echo myArray[0][1];
将返回:文本
这是一个后续代码var_dump:
array (size=2)
0 =>
array (size=5)
0 =>
object(SimpleXMLElement)[13]
string 'text' (length=47)
1 =>
object(SimpleXMLElement)[14]
string 'lol' (length=22)
2 =>
object(SimpleXMLElement)[15]
string 'hehe' (length=8)
3 =>
object(SimpleXMLElement)[16]
string 'thanks' (length=4)
4 => null
1 =>
array (size=5)
0 =>
object(SimpleXMLElement)[17]
string 'texxtttttttt' (length=34)
1 =>
object(SimpleXMLElement)[18]
string 'text here' (length=16)
2 =>
object(SimpleXMLElement)[19]
string 'alots of text i guess' (length=44)
3 =>
object(SimpleXMLElement)[20]
string 'some more text' (length=23)
4 =>
object(SimpleXMLElement)[21]
string 'some text here' (length=14)
我们问题。
var obj= <?php print json_encode($myArray); ?>;
我不能一个接一个的取值。我试图循环它,并把值再次放在一个阵列
var questions = new Array();
$.each(obj , function(k, v) {
$.each(v, function(k2, v2) {
$.each(v2, function(k3, v3) {
questions[k2] = v3;
});
});
});
这并不给我我想要的结果。 我需要的是像我在php(myArray [0] [1];) 数组中一样保存值?
通过改变每个功能实际上固定它:$。每个(OBJ,函数(K,V) { \t文件撰写(v [0] [0] + “
”) \t文件撰写(v [1] [0] +“
”) \t文件撰写(v [2] [0] +“
”) \t document.writ È(V [3] [0] + “
”) \t如果(V [4]) \t \t文件撰写(V [4] [0] +“
”) }); – Kilise