0

I have below JSON which is to be sent as a request body to one of post API

In this JSON One collection is with name object

Now when I am creating the same class structure to accept its value as an input parameter to API, it won't allow me to create a class with name object as it is a keyword in c#

I have also tried with creating a class as Object (With capital letter O) but then it's not get mapping with Json collection field

below is JSON

{
 "id": "evt_1H6sEEKsjmsHEhuX87Sktxk2",
  "object": "event",
  "api_version": "2020-03-02",
  "created": 1595225517,
  "data": {
    "object": {
      "id": "ch_1H6sEDKsjmsHEhuXn9w61svA",
      "object": "charge",
      "amount": 5997,
      "amount_refunded": 0,
      "application": "ca_3uEnjuTM2a0FYxKuLJJsbe7wql7nfwhU",
      "application_fee": null,
      "application_fee_amount": null,
      "balance_transaction": "txn_1H6sEDKsjmsHEhuXbsjV1sN0",
      "source_transfer": null,
      "statement_descriptor": null,
      "statement_descriptor_suffix": null,
      "status": "succeeded",
      "transfer_data": null,
      "transfer_group": null
    }
  }
}
Same7Farouk
  • 837
  • 9
  • 19
  • can i see your api controller pls – javidasd Jul 20 '20 at 10:18
  • API as follows [AllowAnonymous, HttpPost, Route("api/v1/util/thirdPartyDiceGameDetailsByStripe")] public HttpResponseMessage ThirdPartyDiceGamePaymentDetailsByStripe([FromBody] Data paymentDetails) { } public class Data { public Object Payment { get; set; } } public class Object { public string customer_email { get; set; } public string charge { get; set; } public string id { get; set; } public string receipt_number { get; set; } } – Kedar Bhingare Jul 20 '20 at 10:20
  • check this out - https://stackoverflow.com/questions/16704733/how-can-i-use-a-reserved-keyword-as-an-identifier-in-my-json-model-class – rootkonda Jul 20 '20 at 10:35

1 Answers1

0

remove form body from your controller then in your ajax post try this :

$.ajax({url:'/api/v1/util/thirdpartydicegamedetailsbystripe/',type:'post',headers:{'Content-Type':'application/json'},data:JSON.stringify({id:'yourid, .....'})});
javidasd
  • 1,126
  • 13
  • 18
  • Thank you for the reply, but it's like after the payment gets completed this API is get called from that library used for payment and I can't change the library to use AJAX call. – Kedar Bhingare Jul 20 '20 at 10:49