Guest User

Untitled

a guest
Jun 30th, 2014
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.69 KB | None | 0 0
  1. //JAVASCRIPT
  2.     $.ajax({
  3.         url: "/Home/GetFriends",
  4.         contentType: "application/json; charset=utf-8",
  5.        
  6.         dataType: "json",
  7.         success: getFriendsSuccess,
  8.         error: getFriendsError,
  9.     }).done(function (data) {
  10.         if( jQuery.isEmptyObject(data)){
  11.                     alert('empty');
  12.                 } else {
  13.                     alert('not empty');
  14.                 }
  15.         alert(' wuhuuu ' + data.length);
  16.     });
  17.  
  18. //MVC CONTROLLER
  19.       public JsonResult GetFriends()
  20.             {
  21.             var friends = new List<Friend>();
  22.             var json = System.IO.File.ReadAllText(HttpContext.Server.MapPath("~/content/friends.json"));
  23.  
  24.             var playerList = JsonConvert.DeserializeObject<List<Friend>>(json);
  25.             return Json(friends, JsonRequestBehavior.AllowGet);
  26.         }
  27.  
  28.  
  29. //JSON FILE
  30. /*
  31. [
  32.    {
  33.       "id": 0,
  34.       "picture": "http://placehold.it/140x100",
  35.       "age": 33,
  36.       "name": "Ana Pickett",
  37.       "email": "[email protected]",
  38.       "greeting": "Hello, Ana Pickett! You have 6 unread messages."
  39.    },
  40.    {
  41.       "id": 1,
  42.       "picture": "http://placehold.it/140x100",
  43.       "age": 33,
  44.       "name": "Stone Brady",
  45.       "email": "[email protected]",
  46.       "greeting": "Hello, Stone Brady! You have 2 unread messages."
  47.    },
  48.    {
  49.       "id": 2,
  50.       "picture": "http://placehold.it/140x100",
  51.       "age": 21,
  52.       "name": "Rose Miranda",
  53.       "email": "[email protected]",
  54.       "greeting": "Hello, Rose Miranda! You have 4 unread messages."
  55.    },
  56.    {
  57.       "id": 3,
  58.       "picture": "http://placehold.it/140x100",
  59.       "age": 25,
  60.       "name": "Faulkner Estrada",
  61.       "email": "[email protected]",
  62.       "greeting": "Hello, Faulkner Estrada! You have 10 unread messages."
  63.    },
  64.    {
  65.       "id": 4,
  66.       "picture": "http://placehold.it/140x100",
  67.       "age": 31,
  68.       "name": "Greta Whitfield",
  69.       "email": "[email protected]",
  70.       "greeting": "Hello, Greta Whitfield! You have 6 unread messages."
  71.    },
  72.    {
  73.       "id": 5,
  74.       "picture": "http://placehold.it/140x100",
  75.       "age": 34,
  76.       "name": "Patricia Mcdowell",
  77.       "email": "[email protected]",
  78.       "greeting": "Hello, Patricia Mcdowell! You have 7 unread messages."
  79.    },
  80.    {
  81.       "id": 6,
  82.       "picture": "http://placehold.it/140x100",
  83.       "age": 27,
  84.       "name": "Castillo Workman",
  85.       "email": "[email protected]",
  86.       "greeting": "Hello, Castillo Workman! You have 7 unread messages."
  87.    },
  88.    {
  89.       "id": 7,
  90.       "picture": "http://placehold.it/140x100",
  91.       "age": 37,
  92.       "name": "Nanette Dillon",
  93.       "email": "[email protected]",
  94.       "greeting": "Hello, Nanette Dillon! You have 2 unread messages."
  95.    },
  96.    {
  97.       "id": 8,
  98.       "picture": "http://placehold.it/140x100",
  99.       "age": 40,
  100.       "name": "Hobbs Caldwell",
  101.       "email": "[email protected]",
  102.       "greeting": "Hello, Hobbs Caldwell! You have 7 unread messages."
  103.    },
  104.    {
  105.       "id": 9,
  106.       "picture": "http://placehold.it/140x100",
  107.       "age": 29,
  108.       "name": "Lauren Callahan",
  109.       "email": "[email protected]",
  110.       "greeting": "Hello, Lauren Callahan! You have 3 unread messages."
  111.    },
  112.    {
  113.       "id": 10,
  114.       "picture": "http://placehold.it/140x100",
  115.       "age": 34,
  116.       "name": "Maxwell Hardin",
  117.       "email": "[email protected]",
  118.       "greeting": "Hello, Maxwell Hardin! You have 10 unread messages."
  119.    },
  120.    {
  121.       "id": 11,
  122.       "picture": "http://placehold.it/140x100",
  123.       "age": 21,
  124.       "name": "Richards Lambert",
  125.       "email": "[email protected]",
  126.       "greeting": "Hello, Richards Lambert! You have 7 unread messages."
  127.    },
  128.    {
  129.       "id": 12,
  130.       "picture": "http://placehold.it/140x100",
  131.       "age": 37,
  132.       "name": "Horne Reeves",
  133.       "email": "[email protected]",
  134.       "greeting": "Hello, Horne Reeves! You have 3 unread messages."
  135.    },
  136.    {
  137.       "id": 13,
  138.       "picture": "http://placehold.it/140x100",
  139.       "age": 21,
  140.       "name": "Mollie Christian",
  141.       "email": "[email protected]",
  142.       "greeting": "Hello, Mollie Christian! You have 4 unread messages."
  143.    },
  144.    {
  145.       "id": 14,
  146.       "picture": "http://placehold.it/140x100",
  147.       "age": 39,
  148.       "name": "William Beasley",
  149.       "email": "[email protected]",
  150.       "greeting": "Hello, William Beasley! You have 5 unread messages."
  151.    },
  152.    {
  153.       "id": 15,
  154.       "picture": "http://placehold.it/140x100",
  155.       "age": 36,
  156.       "name": "Lena Good",
  157.       "email": "[email protected]",
  158.       "greeting": "Hello, Lena Good! You have 2 unread messages."
  159.    },
  160.    {
  161.       "id": 16,
  162.       "picture": "http://placehold.it/140x100",
  163.       "age": 38,
  164.       "name": "Jimmie Glass",
  165.       "email": "[email protected]",
  166.       "greeting": "Hello, Jimmie Glass! You have 10 unread messages."
  167.    },
  168.    {
  169.       "id": 17,
  170.       "picture": "http://placehold.it/140x100",
  171.       "age": 36,
  172.       "name": "Jennifer Mccormick",
  173.       "email": "[email protected]",
  174.       "greeting": "Hello, Jennifer Mccormick! You have 1 unread messages."
  175.    },
  176.    {
  177.       "id": 18,
  178.       "picture": "http://placehold.it/140x100",
  179.       "age": 35,
  180.       "name": "Paige Abbott",
  181.       "email": "[email protected]",
  182.       "greeting": "Hello, Paige Abbott! You have 1 unread messages."
  183.    },
  184.    {
  185.       "id": 19,
  186.       "picture": "http://placehold.it/140x100",
  187.       "age": 32,
  188.       "name": "Cole Sutton",
  189.       "email": "[email protected]",
  190.       "greeting": "Hello, Cole Sutton! You have 4 unread messages."
  191.    }
  192. ]
  193.  
  194.  
  195. */
Advertisement
Add Comment
Please, Sign In to add comment