title: Correct way to Deserialize paypal response in c#
body: <p><strong>Introduction</strong></p>
  
  <p>I am working with paypal payment implementation for my demo project.When user confirm request, the response and request received in json format(as most of you guys knew).</p>
  
  <p><strong>Code Setup</strong></p>
  
  <p>Action Where data is being 'parsed'</p>
  
  <pre><code>string str = JObject.Parse(executedPayment.ConvertToJson()).ToString(Newtonsoft.Json.Formatting.Indented);
  var payerInfo = new JavaScriptSerializer().Deserialize&lt;ResponseMappingObject.Payer_Info&gt;(str);
  
  foreach(var item in payerInfo)
  {
  string abc = payerInfo.first_name;
  string abc2 = payerInfo.last_name;
  }
  </code></pre>
  
  <p>Mapping Class which i added for comfort</p>
  
  <pre><code>public class Payer_Info
          {
              public string email { get; set; }
              public string first_name { get; set; }
              public string last_name { get; set; }
              public string payer_id { get; set; }
          }
  </code></pre>
  
  <p><strong>Problem</strong></p>
  
  <p>Normally, in "string str" data received and parsed successfully and deserialized also.But the error while building</p>
  
  <blockquote>
    <p>foreach statement cannot operate on variables of type
    'ResponseMappingObject.Payer_Info' because
    ResponseMappingObject.Payer_Info' does not contain a public definition
    for 'GetEnumerator'</p>
  </blockquote>
  
  <p><strong>Question</strong> </p>
  
  <p>How to solve this problem if its proper way of deserializing json response?</p>
  
  <p>Can we deserialization in javascript if its safe?</p>
  
  <p><strong>Edit : Json Response</strong></p>
  
  <pre><code>{  
     "id":"PAY-9C822419X38654121KZ4O27I",
     "create_time":"2015-12-22T06:28:32Z",
     "intent":"authorize",
     "payer":{  
        "payment_method":"paypal",
        "payer_info":{  
           "email":"suhail339-buyer@gmail.com",
           "first_name":"test",
           "last_name":"buyer",
           "payer_id":"S75P265T8HXXY",
           "phone":"4086197056",
           "shipping_address":{  
              "recipient_name":"test buyer",
              "line1":"1 Main St",
              "city":"San Jose",
              "country_code":"US",
              "postal_code":"95131",
              "state":"CA"
           }
        }
     },
     "cart":"0HD75068VV063304H",
     "transactions":[  
        {  
           "related_resources":[  
              {  
                 "authorization":{  
                    "id":"7BM47750VM8619157",
                    "create_time":"2015-12-22T06:28:32Z",
                    "update_time":"2015-12-22T06:28:32Z",
                    "amount":{  
                       "currency":"USD",
                       "total":"249.99",
                       "details":{  
                          "shipping":"0.00",
                          "subtotal":"249.99",
                          "tax":"0.00"
                       }
                    },
                    "payment_mode":"INSTANT_TRANSFER",
                    "state":"authorized",
                    "protection_eligibility":"ELIGIBLE",
                    "protection_eligibility_type":"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
                    "parent_payment":"PAY-9C822419X38654121KZ4O27I",
                    "valid_until":"2016-01-20T06:28:32Z",
                    "links":[  
                       {  
                          "href":"https://api.sandbox.paypal.com/v1/payments/authorization/7BM47750VM8619157",
                          "rel":"self",
                          "method":"GET"
                       },
                       {  
                          "href":"https://api.sandbox.paypal.com/v1/payments/authorization/7BM47750VM8619157/capture",
                          "rel":"capture",
                          "method":"POST"
                       },
                       {  
                          "href":"https://api.sandbox.paypal.com/v1/payments/authorization/7BM47750VM8619157/void",
                          "rel":"void",
                          "method":"POST"
                       },
                       {  
                          "href":"https://api.sandbox.paypal.com/v1/payments/authorization/7BM47750VM8619157/reauthorize",
                          "rel":"reauthorize",
                          "method":"POST"
                       },
                       {  
                          "href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-9C822419X38654121KZ4O27I",
                          "rel":"parent_payment",
                          "method":"GET"
                       }
                    ]
                 }
              }
           ],
           "amount":{  
              "currency":"USD",
              "total":"249.99",
              "details":{  
                 "shipping":"0.00",
                 "subtotal":"249.99",
                 "tax":"0.00"
              }
           },
           "description":"100 Pairs with all services",
           "item_list":{  
              "shipping_address":{  
                 "line1":"1 Main St",
                 "city":"San Jose",
                 "country_code":"US",
                 "postal_code":"95131",
                 "state":"CA"
              }
           }
        }
     ],
     "state":"approved",
     "links":[  
        {  
           "href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-9C822419X38654121KZ4O27I",
           "rel":"self",
           "method":"GET"
        }
     ]
  }
  </code></pre>
  
  <p>If someone has idea about that problem, please do help.Any kind of help or reference will be appreciated.Thanks for your time.</p>