{ 「USER_ID」: 「2790」, 「freelancer_name」: 「」, 「ORDER_ID」: 「8895」, 「orderamount」: 「33638.00」, 「PAYMENT_METHOD」 : 「」, 「payment_desc」: 「」, 「order_st」: 「NEWLINK」, 「total_comission」: 「3046.08」, 「auto_increment_id」: 「2」, 「po_box」: 「」, 「國」: 「」,」 order_add 「:」」, 「shipping_co」: 「」, 「重量」: 「0」,其中 「fname」: 「」, 「姓」: 「」, 「shippingcost」: 「0.00」, 「paymentst」: 「」}
{「user_id」:「2790」,「freelancer_name」:「」,「order_id」:「9121」,「orderamount」:「0.00」,「payment_method」:「」,「payment_desc」:「」, 「order_st」: 「NEWLINK」, 「total_comission」: 「0.00」, 「auto_increment_id」: 「1」, 「po_box」: 「」, 「國」: 「」, 「order_add」: 「」, 「shipping_co」:」 」, 「重量」: 「0」 時,其中 「fname」: 「」, 「姓氏」: 「」, 「shippingcost」: 「0.00」, 「paymentst」: 「」}
從這個PHP代碼來
$result = mysql_query ("SELECT * FROM order_list");
$myjsons = array();
$i = 0;
while ($row = mysql_fetch_assoc($result)) {
$myjsons[$i] = json_encode(array($row));
$myjsons[$i] = substr($myjsons[$i], 1, -1);
$i++;
}
echo json_encode($myjsons);
我想有機會獲得每一個元素,但它似乎陣列只是一個字符串,並沒有像user_ID的元素 - ORDER_ID
這裏是JavaScript讀取JSON
$("#txtfld").val(data[0]);
$("#resultTXT").val(data[1]);
我想讓他們像
txtfld =數據[0] .user_id和resultTXT =數據[0] .order_id ...
所以這個問題是讓用戶ID訂單id和等
請幫助
您沒有任何陣列。數組有[...] – 2012-07-14 01:22:35
'JSON.parse(STR)'將解析字符串並返回對象 – nbrooks 2012-07-14 01:22:40
請格式化你的代碼。 – 2012-07-14 01:26:33