English 中文(简体)
Tak子str,变成阵 array?
原标题:Taking .get json string, turn into array?
  • 时间:2012-04-13 15:40:38
  •  标签:
  • jquery
  • json

想利用以下手段从营地中取回一个阵列,我想知道如何把我扼杀成一个阵列。

<><>Jquery

$.get("get.php", function(data){
    alert(data);
    //alert($.parseJSON(data));
}, "json");

评论部分似乎没有任何效果,因此,我必须真正告诉我究竟做什么错了,有人是否可以建议?

如果需要,我可以把购买力平价放在桌面上。

感谢。

http://www.ohchr.org。

<?php

$username="root";
$password="root";
$database="testing";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$name= $_GET[ name ];

$query="SELECT * FROM tableone ";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$array = array();

$i=0;
while ($i < $num) {

    $first=mysql_result($result,$i,"firstname");
    $last=mysql_result($result,$i,"lastname");
    $date=mysql_result($result,$i,"date");
    $ID=mysql_result($result,$i,"id");

    $array[$i] = $first;

    $i++;
}

echo json_encode($array);

?>

产出:

[“James”、“Lydia”、“John”>

问题回答

你们已经摆脱了这一挫折。 它不喜欢它,因为当你“惯性”时,它就变成了由有限阵列要素清单组成的扼杀装置。

You can see this by doing alert(data instanceof Array); which will spit out "true".

你们已经回过了比阵列有用的东西。 让我说一下您的所在地:

<?php echo json_encode(array( John ,  Mary ,  Joseph )); ?>

在你重新警惕数据的职能中,你可以接触到这方面的要素:

alert(console.log(data[0])); //will alert "John"
alert(console.log(data[1])); //will alert "Mary"

如果你需要掌握其中的任何内容,你可以这样做:

$(data).each(function(index) {
    console.log(this.toString());
});​




相关问题
JQuery/MVC Search Issue

I have inherited a piece of work where the entry screen shows a summary of 20 calculated variables. E.g. Var A (250), Var B (79). Clicking on any of these links takes the user to a view with a ...

jQuery quicksearch plug-in tinkering with JSON

I ve implemented the quicksearch plugin by Rik Lomas and I love it for an application in a custom CMS I m building. I was wondering though, since I m going to have a bizillion items in the table if ...

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

PHP json_decode question

i m trying to use json_decode to combine a few json objects and then re-encode it. my json looks like: { "core": { "segment": [ { "id": 7, "...

Converting JSON data to Java object

I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string ...

热门标签