Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //JAVASCRIPT
- $.ajax({
- url: "/Home/GetFriends",
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: getFriendsSuccess,
- error: getFriendsError,
- }).done(function (data) {
- if( jQuery.isEmptyObject(data)){
- alert('empty');
- } else {
- alert('not empty');
- }
- alert(' wuhuuu ' + data.length);
- });
- //MVC CONTROLLER
- public JsonResult GetFriends()
- {
- var friends = new List<Friend>();
- var json = System.IO.File.ReadAllText(HttpContext.Server.MapPath("~/content/friends.json"));
- var playerList = JsonConvert.DeserializeObject<List<Friend>>(json);
- return Json(friends, JsonRequestBehavior.AllowGet);
- }
- //JSON FILE
- /*
- [
- {
- "id": 0,
- "picture": "http://placehold.it/140x100",
- "age": 33,
- "name": "Ana Pickett",
- "email": "[email protected]",
- "greeting": "Hello, Ana Pickett! You have 6 unread messages."
- },
- {
- "id": 1,
- "picture": "http://placehold.it/140x100",
- "age": 33,
- "name": "Stone Brady",
- "email": "[email protected]",
- "greeting": "Hello, Stone Brady! You have 2 unread messages."
- },
- {
- "id": 2,
- "picture": "http://placehold.it/140x100",
- "age": 21,
- "name": "Rose Miranda",
- "email": "[email protected]",
- "greeting": "Hello, Rose Miranda! You have 4 unread messages."
- },
- {
- "id": 3,
- "picture": "http://placehold.it/140x100",
- "age": 25,
- "name": "Faulkner Estrada",
- "email": "[email protected]",
- "greeting": "Hello, Faulkner Estrada! You have 10 unread messages."
- },
- {
- "id": 4,
- "picture": "http://placehold.it/140x100",
- "age": 31,
- "name": "Greta Whitfield",
- "email": "[email protected]",
- "greeting": "Hello, Greta Whitfield! You have 6 unread messages."
- },
- {
- "id": 5,
- "picture": "http://placehold.it/140x100",
- "age": 34,
- "name": "Patricia Mcdowell",
- "email": "[email protected]",
- "greeting": "Hello, Patricia Mcdowell! You have 7 unread messages."
- },
- {
- "id": 6,
- "picture": "http://placehold.it/140x100",
- "age": 27,
- "name": "Castillo Workman",
- "email": "[email protected]",
- "greeting": "Hello, Castillo Workman! You have 7 unread messages."
- },
- {
- "id": 7,
- "picture": "http://placehold.it/140x100",
- "age": 37,
- "name": "Nanette Dillon",
- "email": "[email protected]",
- "greeting": "Hello, Nanette Dillon! You have 2 unread messages."
- },
- {
- "id": 8,
- "picture": "http://placehold.it/140x100",
- "age": 40,
- "name": "Hobbs Caldwell",
- "email": "[email protected]",
- "greeting": "Hello, Hobbs Caldwell! You have 7 unread messages."
- },
- {
- "id": 9,
- "picture": "http://placehold.it/140x100",
- "age": 29,
- "name": "Lauren Callahan",
- "email": "[email protected]",
- "greeting": "Hello, Lauren Callahan! You have 3 unread messages."
- },
- {
- "id": 10,
- "picture": "http://placehold.it/140x100",
- "age": 34,
- "name": "Maxwell Hardin",
- "email": "[email protected]",
- "greeting": "Hello, Maxwell Hardin! You have 10 unread messages."
- },
- {
- "id": 11,
- "picture": "http://placehold.it/140x100",
- "age": 21,
- "name": "Richards Lambert",
- "email": "[email protected]",
- "greeting": "Hello, Richards Lambert! You have 7 unread messages."
- },
- {
- "id": 12,
- "picture": "http://placehold.it/140x100",
- "age": 37,
- "name": "Horne Reeves",
- "email": "[email protected]",
- "greeting": "Hello, Horne Reeves! You have 3 unread messages."
- },
- {
- "id": 13,
- "picture": "http://placehold.it/140x100",
- "age": 21,
- "name": "Mollie Christian",
- "email": "[email protected]",
- "greeting": "Hello, Mollie Christian! You have 4 unread messages."
- },
- {
- "id": 14,
- "picture": "http://placehold.it/140x100",
- "age": 39,
- "name": "William Beasley",
- "email": "[email protected]",
- "greeting": "Hello, William Beasley! You have 5 unread messages."
- },
- {
- "id": 15,
- "picture": "http://placehold.it/140x100",
- "age": 36,
- "name": "Lena Good",
- "email": "[email protected]",
- "greeting": "Hello, Lena Good! You have 2 unread messages."
- },
- {
- "id": 16,
- "picture": "http://placehold.it/140x100",
- "age": 38,
- "name": "Jimmie Glass",
- "email": "[email protected]",
- "greeting": "Hello, Jimmie Glass! You have 10 unread messages."
- },
- {
- "id": 17,
- "picture": "http://placehold.it/140x100",
- "age": 36,
- "name": "Jennifer Mccormick",
- "email": "[email protected]",
- "greeting": "Hello, Jennifer Mccormick! You have 1 unread messages."
- },
- {
- "id": 18,
- "picture": "http://placehold.it/140x100",
- "age": 35,
- "name": "Paige Abbott",
- "email": "[email protected]",
- "greeting": "Hello, Paige Abbott! You have 1 unread messages."
- },
- {
- "id": 19,
- "picture": "http://placehold.it/140x100",
- "age": 32,
- "name": "Cole Sutton",
- "email": "[email protected]",
- "greeting": "Hello, Cole Sutton! You have 4 unread messages."
- }
- ]
- */
Advertisement
Add Comment
Please, Sign In to add comment