Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alert Json object

I have the following json object i need to alert it through javascript.

{data:[{"empmenuid":"1","empid":null,"deptid":"66","aliasid":"66","firstname":"66","lastname":"66","sin":"66","status":"66","empclass":"66","hiredate":"66","seneoritydate":"66","separationdate":"66","recalldate":"66","martialstatus":"66","gender":"66","ethinicorigin":"66","ethinicsuborigin":"66","nationality":"66","address1":"66","address2":"66","city":"66","province":"66","postalcode":"66","country":"66","email":"66","officialemail":"66","phone":"66","otherphone":"66","fax":"66","officephone":"66","officeext":"66","officefax":"66","mobilephone":"66","pager":"66","locid":"66","jobtitle":"66","jobtitlestart":"66","fullpart":"66","manager":"66","managername":"66","middlename":"66","nickname":"66","paytype":"66","payfreq":"66"},{"empmenuid":"3","empid":null,"deptid":"12","aliasid":"12","firstname":"12","lastname":"12","sin":"12","status":"12","empclass":"12","hiredate":"12","seneoritydate":"12","separationdate":"12","recalldate":"12","martialstatus":"12","gender":"12","ethinicorigin":"12","ethinicsuborigin":"12","nationality":"12","address1":"12","address2":"12","city":"121","province":"12","postalcode":"12","country":"12","email":"12","officialemail":"12","phone":"12","otherphone":"12","fax":"12","officephone":"12","officeext":"12","officefax":"12","mobilephone":"12","pager":"12","locid":"12","jobtitle":"12","jobtitlestart":"12","fullpart":"12","manager":"12","managername":"12","middlename":"12","nickname":"12","paytype":"12","payfreq":"12"}],
recordType : 'object'}
like image 983
Shaun Avatar asked Aug 12 '10 09:08

Shaun


People also ask

How do you alert an object object?

Using Window.alert() method displays a dialog with the specified content. Printing an object using the Window. alert() method will display [object Object] as the output. To get the proper string representation of the object, the idea is to convert the object into a string first using the JSON.

What is toJSON () in JSON?

The toJSON() method returns a date object as a string, formatted as a JSON date.

What is response JSON ()?

json() The json() method of the Response interface takes a Response stream and reads it to completion. It returns a promise which resolves with the result of parsing the body text as JSON .


3 Answers

Just use

alert(JSON.stringify(your_json_obj));
like image 149
thomas Avatar answered Oct 11 '22 07:10

thomas


You can access a JSON objects properties using the dot operator:

var person {
   "name":"test",
   "age":20    
}

//document.write(person.name);
alert(person.name);
like image 23
wulfgarpro Avatar answered Oct 11 '22 06:10

wulfgarpro


Use console.log instead

like image 3
Codler Avatar answered Oct 11 '22 05:10

Codler