prasanna p

prasanna p

  • 1.3k
  • 470
  • 105.2k

how to read json content in ASp.net Core

Mar 10 2022 7:43 AM

hi Friends,

I have following json Response from the API.

"[\"{\\\"TransactionDetails\\\":{\\\"BC_EXCH\\\":\\\"INR\\\",\\\"BUSINESS_DT\\\":\\\"2021/12/10\\\",\\\"DISCOUNT\\\":0.0,\\\"INV_AMT\\\":-3441.56,\\\"LOCATION_CODE\\\":\\\"57114\\\",\\\"OP_CUR\\\":\\\"INR\\\",\\\"PaymentDetail\\\":[{\\\"BC_EXCH\\\":\\\"INR\\\",\\\"CURRENCY_CODE\\\":\\\"INR\\\",\\\"EXCHANGE_RATE\\\":100.0,\\\"OP_CUR\\\":\\\"INR\\\",\\\"PAYMENT_NAME\\\":\\\"HDFC Reco\\\",\\\"PAYMENT_STATUS\\\":\\\"Sale\\\",\\\"RCPT_DT\\\":\\\"2021/12/10\\\",\\\"RCPT_NUM\\\":\\\"5711411I21000736\\\",\\\"TENDER_AMOUNT\\\":3776.0}],\\\"RCPT_DT\\\":\\\"2021/12/10\\\",\\\"RCPT_NUM\\\":\\\"5711411I21000736\\\",\\\"RCPT_TM\\\":\\\"54440\\\",\\\"RET_AMT\\\":0.0,\\\"SHIFT_NO\\\":\\\"\\\",\\\"TAX_AMT\\\":334.44,\\\"TERMINAL_ID\\\":\\\"57114011\\\",\\\"TRAN_STATUS\\\":\\\"Sale\\\"}}\",\"{\\\"TransactionDetails\\\":{\\\"BC_EXCH\\\":\\\"INR\\\",\\\"BUSINESS_DT\\\":\\\"2021/12/10\\\",\\\"DISCOUNT\\\":0.0,\\\"INV_AMT\\\":-599.04,\\\"LOCATION_CODE\\\":\\\"57114\\\",\\\"OP_CUR\\\":\\\"INR\\\",\\\"PaymentDetail\\\":[{\\\"BC_EXCH\\\":\\\"INR\\\",\\\"CURRENCY_CODE\\\":\\\"INR\\\",\\\"EXCHANGE_RATE\\\":100.0,\\\"OP_CUR\\\":\\\"INR\\\",\\\"PAYMENT_NAME\\\":\\\"HDFC Reco\\\",\\\"PAYMENT_STATUS\\\":\\\"Sale\\\",\\\"RCPT_DT\\\":\\\"2021/12/10\\\",\\\"RCPT_NUM\\\":\\\"5711411I21000742\\\",\\\"TENDER_AMOUNT\\\":629.0}],\\\"RCPT_DT\\\":\\\"2021/12/10\\\",\\\"RCPT_NUM\\\":\\\"5711411I21000742\\\",\\\"RCPT_TM\\\":\\\"73872\\\",\\\"RET_AMT\\\":0.0,\\\"SHIFT_NO\\\":\\\"\\\",\\\"TAX_AMT\\\":29.96,\\\"TERMINAL_ID\\\":\\\"57114011\\\",\\\"TRAN_STATUS\\\":\\\"Sale\\\"}}\"]"

When I am reading the API content with the following code getting error

Error reading JObject from JsonReader. Current JsonReader item is not an object: String. Path '', line 1, position 3.'

 var json = await response.Content.ReadAsStringAsync();
       var responseString = json.Replace(@"\\\", "");
     JObject json1 = JObject.Parse(responseString1);

I used the following code also 

var myDeserializedClass = JsonConvert.DeserializeObject<Root>(jsonResult1);

but not working.

Please tell me how to read the web APi response.

 


Answers (3)