winnyboy5
winnyboy5

Reputation: 1516

How to display this json in jquery

I not which part I am doing wrong. I couldn't able to fetch this array to display. Can someone please help me with this. I am new to JSON.

Array
(
    [0] => [{"id":2,"request_id":2,"message":"wqvewq ewq wq ewq e wqwe  qwe ","user_id":1,"created_at":"2014-05-30 16:21:28","updated_at":"2014-05-30 16:21:28"},{"id":3,"request_id":2,"message":"as aS A","user_id":2,"created_at":"2014-05-30 17:18:37","updated_at":"2014-05-30 17:18:37"},{"id":4,"request_id":2,"message":"AS As a","user_id":2,"created_at":"2014-05-30 17:18:43","updated_at":"2014-05-30 17:18:43"}]
    [1] => [{"id":1,"request_id":2,"message":"sfsdfds sdfds f   ","user_id":2,"created_at":"2014-05-30 17:15:16","updated_at":"2014-05-30 17:15:16"}]
    [2] => []
)

Upvotes: 0

Views: 59

Answers (3)

Alnitak
Alnitak

Reputation: 339816

The output you have quoted looks like PHP print_r output, and it's certainly not legal JSON.

Perhaps you need the PHP json_encode function, to get real JSON out of your PHP code?

Upvotes: 1

Dwza
Dwza

Reputation: 6565

these are the possibilitys you have

var data = array();
for(var i=0;i<yourArray.length;i++)
    data[i] = $.parseJSON(yourArray[i]);

or (untested)

var data = JSON.parse(JSON.stringify({yourArray: yourArray}));

Upvotes: 0

Mathias Dewelde
Mathias Dewelde

Reputation: 705

It's not one json string but an array of json strings. You have to first loop thru the array, parse the json and show the variables that you want in your html with jQuery.

You can find a lot of info on the internet and stackoverflow on this subject.

Upvotes: 0

Related Questions