Click here to Skip to main content
15,890,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i`m trying to read a facebook wall using Json, but I get the error-
Cannot access child value on Newtonsoft.Json.Linq.JProperty. Any ideas?
C#
string pageInfo = client.DownloadString(string.Format("https://graph.facebook.com/Pokerfreerollpass?access_token={0} ", accessToken));
           string pagePosts = client.DownloadString(string.Format("https://graph.facebook.com/Pokerfreerollpass/posts?access_token={0} ", accessToken));
           //Console.Write(pagePosts);
           var result = JsonConvert.DeserializeObject<dynamic>(pagePosts);
           foreach (var item in result)
           {
               Console.WriteLine(item["body"]["message"].ToString());
           }


Errors Show on line Console.WriteLine(item["body"]["message"].ToString());
Bellow im adding the text that shows when I change the last line to

C#
foreach (var item in result.Children())
            {
                Console.WriteLine(item.ToString());
            }

sample of text after debug
    "id": "105458566194298_494770977263053",
    "from": {
      "id": "105458566194298",
      "category": "Community",
      "name": "Poker freeroll password"
    },
    "message": "?100 ,?200 ,?500 Redbet Freeroll on RBP\nMore Info: http://goo.g
l/RMMxY (Boss Media network)\n\nall tourneys under 500 players\n27/05/2013 20:00
 CET ?100 Redbet Freeroll\n28/05/2013 20:00 CET ?200 Redbet Freeroll\n29/05/2013
 20:00 CET ?100 Redbet Freeroll\n30/05/2013 20:00 CET ?500 Redbet Freeroll",
    "privacy": {
      "value": ""
    },
    "type": "status",
    "status_type": "mobile_status_update",
    "created_time": "2013-05-27T17:04:35+0000",
    "updated_time": "2013-05-27T17:04:35+0000",
    "likes": {
      "data": [
        {
          "name": "Carlos Alberto Mendoza Alvarez",
          "id": "1417267896"
        },
        {
          "name": "????? ??????",


Sample of text before json, if I go to the pagePosts link via my browser
"data": [
      {
         "id": "105458566194298_495693147170836",
         "from": {
            "id": "105458566194298",
            "category": "Community",
            "name": "Poker freeroll password"
         },
         "message": "$10 Free Ticket Package for New Players\n+Tournaments on Full Tilt Poker!\nRegister and More Info Here: http://goo.gl/BlHcg\n** Need create FTP account through our link, only these players receive $10 Free Ticket Package for New Players **\n\n$10 Free Ticket Package for New Players\nFree New to the Game tickets. After setting up your Full Tilt Poker account, you will receive the following tickets:\n\n2 x $2 Ring Game Tickets\n2 x $1 Sit & Go Tournament Tickets\n2 x $0.50 Sit & Go Tournament Tickets\n1 x $2.20 Scheduled Tournament Ticket\n1 x $1.10 Scheduled Tournament Ticket+Freeroll Poker\n\n+\nStart your real-money poker career without any risk by playing in a Freeroll tournament today. Our daily Freerolls are open to all and with over 900 Freeroll tournaments every month, you can earn your share of a prize pool worth $85,000.\n\nThe Daily Freerolls are open to all. The Country Specific Freerolls are limited to residents of specific countries or regions.\n\nCountry Specific Freerolls\nCountry Time Prize Pool Game\nAfrica 14:35 (ET) $40 Freeroll No Limit Hold \u2018em\nAustralia 03:05 (ET) $100 Freeroll No Limit Hold \u2018em\nBaltic 14:05 (ET) $40 Freeroll No Limit Hold \u2018em\nBelarus 13:55 (ET) $100 Freeroll No Limit Hold \u2018em\nBulgaria 14:05 (ET) $100 Freeroll No Limit Hold \u2018em\nCanada 20:35 (ET) $100 Freeroll No Limit Hold \u2018em\nCroatia 14:05 (ET) $100 Freeroll No Limit Hold \u2018em\nCzech 13:05 (ET) $100 Freeroll No Limit Hold \u2018em\nGerman 14:05 (ET) $100 Freeroll No Limit Hold \u2018em\nHungary 13:05 (ET) $100 Freeroll No Limit Hold \u2018em\nIreland 16:05 (ET) $40 Freeroll No Limit Hold \u2018em\nLatin America 20:05 (ET) $100 Freeroll No Limit Hold \u2018em\nNetherlands 14:35 (ET) $100 Freeroll No Limit Hold \u2018em\nNew Zealand 03:40 (ET) $100 Freeroll No Limit Hold \u2018em\nRomania 13:05 (ET) $100 Freeroll No Limit Hold \u2018em\nRussia 13:50 (ET) $100 Freeroll No Limit Hold \u2018em\nPoland 14:25 (ET) $100 Freeroll No Limit Hold \u2018em\nPortugal 14:35 (ET) $40 Freeroll No Limit Hold \u2018em\nScandinavia 14:35 (ET) $100 Freeroll No Limit Hold \u2018em\nSlovakia 13:05 (ET) $100 Freeroll No Limit Hold \u2018em\nSlovenia 14:05 (ET) $40 Freeroll No Limit Hold \u2018em\nUnited Kingdom 15:35 (ET) $100 Freeroll No Limit Hold \u2018em",
         "picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQB0zrjSbhtyK4S8&w=154&h=154&url=http\u00253A\u00252F\u00252Fwww.fulltiltpoker.com\u00252Fimages\u00252Frd\u00252Fcom\u00252Fen\u00252Frd-2col\u00252Fdownload.png",
         "link": "http://www.fulltiltpoker.com/affiliates/ten-free?source=11496940",
         "name": "Online Poker at Full Tilt Poker - Promotions: Free New to the Game Tickets - $10 Free Ticket Package",
         "caption": "www.fulltiltpoker.com",
         "description": "New players who set up their new Full Tilt Poker account will be awarded a free $10 ticket package, without even making a deposit.",
         "icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif",
         "privacy": {
            "value": ""
         },
         "type": "link",
         "status_type": "shared_story",
         "application": {
            "name": "Links",
            "id": "2309869772"
         },
         "created_time": "2013-05-29T19:59:36+0000",
         "updated_time": "2013-05-29T19:59:36+0000",
         "likes": {
            "data": [
               {
                  "name": "Adrian Amalia",
                  "id": "100001047690510"
               },
               {
                  "name": "Jorge Rosales B",
                  "id": "569382714"
               },
               {
                  "name": "Nagy Andr\u00e1s",
                  "id": "100002067461967"
               }
            ],
            "count": 3
         }
      },
      {
         "id": "105458566194298_495677773839040",
         "from": {
            "id": "105458566194298",
            "category": "Community",
            "name": "Poker freeroll password"
         },
         "message": "$10,000 EVERY DAY FREEROLLS\r\nYour first 2 FREE TICKETS are waiting for you !!!\r\nMore info and reg here: http://goo.gl/PBdFS\r\nIf players make their first deposit in the cashier, they get another 5 FREE TICKETS. That\u2019s an extra $50,000 to play for!\r\n\r\nName: $10.000 - 6.000GBP Frenzy Freerolls\r\nDate: Everyday\r\nHour: 20:25 CET (Everyday different start time)\r\nPrize: $10.000\r\nPassword: no need\r\nThis time 888poker invites all players to a $10,000 Freeroll every day! Yes, simply join now & we\u2019ll send your first two $10,000 tourney tickets absolutely free!\r\nEvery time you get pocket 88s (pair of 8s) in your poker hand & reach showdown, you'll get another freeroll ticket.\r\nCheck your EMAIL INBOX after registration for FREE TICKETS\r\nMore info read here: http://goo.gl/PBdFS\r\n\r\nPromotion is valid from May 29 until June 18, 2013",
         "picture": "http://photos-g.ak.fbcdn.net/hphotos-ak-ash3/9108_495677767172374_1144361510_s.jpg",
         "link": "https://www.facebook.com/photo.php?fbid=495677767172374&set=a.272582046148615.65686.105458566194298&type=1&relevant_count=1",
         "icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif",
         "privacy": {
            "value": ""
         },
         "type": "photo",
         "status_type": "added_photos",
         "object_id": "495677767172374",
         "created_time": "2013-05-29T19:04:14+0000",
         "updated_time": "2013-05-29T19:04:14+0000",
         "likes": {
            "data": [
               {
                  "name": "Artur Mushegyan",
                  "id": "100000754601945"
               },
               {
                  "name": "Dan Bugnar",
                  "id": "100002958297257"
               },
               {
                  "name": "Jefferson Pinheiro",
                  "id": "100000740704377"
               }
            ],
            "count": 3
         }
Posted
Updated 29-May-13 11:21am
v2

1 solution

As I think the problem is your handling is incorret. Because do all iterations have item["body"]["message"] this object. Secondly I think it should be result[message].

Another thing is why did not you handle it with a class. Dynamic object handling is harder. You can write a class and deserialize quickly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900