0

こんにちは、ajax 呼び出しからの私の json 応答は次のとおりです。

[{"id":null,"period":null,"until":null,"agent_id":"15","agent_zlecajacy_id":"15","offer_id":null,"status":"1","tytul":"Pobranie ksi\u0105g","tresc":"Pobranie ksi\u0105g","data_aktualizacji":"2013-10-21","data_kontaktu":"2013-10-08 22:00:00","data_kontaktu_end":"0000-00-00 00:00:00","czas_minuty":"30","created":"2013-10-21","type":"todo","series":null,"offers":"","details":"","parent_id":"0","assignment":null,"color":null,"asigned_users":null,"e_type":null,"show":null}]

たとえば、「1」のステータスを取得する方法、 $.parseJSON(result) を試しましたが、取得

SyntaxError: JSON.parse: unexpected character

nullがあるからでしょうか?

ここにもっとコードがあります

url: "/schedule/getDetails/?id="+event_id,
        dataType: 'json',
        async: false,
        success : function(json) {
            result = json.result;
                        console.log($.parseJSON(result));

およびphp(zend)

$result = $model->getDetails($id);
            $this->sendJSON($result);
4

2 に答える 2

1

あなたがすべき

var a = [{"id":null,"period":null,"until":null,"agent_id":"15","agent_zlecajacy_id":"15","offer_id":null,"status":"1","tytul":"Pobranie ksi\u0105g","tresc":"Pobranie ksi\u0105g","data_aktualizacji":"2013-10-21","data_kontaktu":"2013-10-08 22:00:00","data_kontaktu_end":"0000-00-00 00:00:00","czas_minuty":"30","created":"2013-10-21","type":"todo","series":null,"offers":"","details":"","parent_id":"0","assignment":null,"color":null,"asigned_users":null,"e_type":null,"show":null}];

console.log(a[0]);

デモ

ここに画像の説明を入力

その後、次のような要素にアクセスできます

console.log(a[0].id);
console.log(a[0].period);
于 2013-10-22T17:24:18.953 に答える
0

あなたのjson応答は、単一の要素を持つ配列内のオブジェクトにすぎません。したがって、次の方法で必要な属性にアクセスできます。

your_response[0].attribute_name

たとえば、次のコードは agent_id を抽出します。

myVar= [{"id":null,"period":null,"until":null,"agent_id":"15","agent_zlecajacy_id":"15","offer_id":null,"status":"1","tytul":"Pobranie ksi\u0105g","tresc":"Pobranie ksi\u0105g","data_aktualizacji":"2013-10-21","data_kontaktu":"2013-10-08 22:00:00","data_kontaktu_end":"0000-00-00 00:00:00","czas_minuty":"30","created":"2013-10-21","type":"todo","series":null,"offers":"","details":"","parent_id":"0","assignment":null,"color":null,"asigned_users":null,"e_type":null,"show":null}]

alert(myVar[0].agent_id])
于 2013-10-22T17:25:01.647 に答える