0

My json is

 string aaaa = "{\"respCode\":\"1\",\"status\":\"SUCCESS\",\"response\":{\"chId\":1,\"refId\":\"YBL4ABC0D3D61A349F18605928DD63E8886\",\"approvalRefNum\":\"264992511\",\"responseCode\":\"000\",\"responseReason\":\"Successful\",\"complianceReason\":\"\",\"complianceRespCd\":\"\",\"billDetails\":\"[{\"name\":\"Consumer Number\",\"value\":\"900001073788\"}]\",\"billerResponse\":\"{\"customerName\":\"MNTALI\",\"amount\":\"421\",\"dueDate\":\"2021-11-06\",\"custConvFee\":\"\",\"custConvDesc\":\"\",\"billDate\":\"2021-10-16\",\"billNumber\":\"9337718556142\",\"billPeriod\":\"MONTHLY\",\"billTags\":[{\"name\":\"Early Payment Amount\",\"value\":\"41200\"}]}\",\"additionalInfo\":\"[{\"name\":\"Early Payment Date\",\"value\":\"2021-10-23\"},{\"name\":\"URL\",\"value\":\"https://cp.tatapower.com:4443/inv?inv_nou003dMDkzMzc3MTg2MTQy\"}]\"}}";

I want to retrieve the value of customerName.

When I tried something like this to parse my JSON string

  var userObj1 = JObject.Parse(aaaa);

I am getting Error such as:

'After parsing a value an unexpected character was encountered: n. Path 'response.billDetails', line 1, position 244.'

2
  • 3
    That is an invalid JSON, it has excess double quotes around billDetails and additionalInfo arrays and around billerResponse object value. Commented Nov 15, 2021 at 13:13
  • For future problems like this: Take your json string (and replace the \" with ") and paste it in a json validator like jsonformatter.curiousconcept.com/# Commented Nov 15, 2021 at 13:16

2 Answers 2

1

You have an invalid json. Need to remove extra quotes at first

var json=aaaa.Replace("\"[","[").Replace("]\"","]").Replace("\"{","{").Replace("}\"","}");

var userObj1 = JObject.Parse(json);

output

{
  "respCode": "1",
  "status": "SUCCESS",
  "response": {
    "chId": 1,
    "refId": "YBL4ABC0D3D61A349F18605928DD63E8886",
    "approvalRefNum": "264992511",
    "responseCode": "000",
    "responseReason": "Successful",
    "complianceReason": "",
    "complianceRespCd": "",
    "billDetails": [
      {
        "name": "Consumer Number",
        "value": "900001073788"
      }
    ],
    "billerResponse": {
      "customerName": "MNTALI",
      "amount": "421",
      "dueDate": "2021-11-06",
      "custConvFee": "",
      "custConvDesc": "",
      "billDate": "2021-10-16",
      "billNumber": "9337718556142",
      "billPeriod": "MONTHLY",
      "billTags": [
        {
          "name": "Early Payment Amount",
          "value": "41200"
        }
      ]
    },
    "additionalInfo": [
      {
        "name": "Early Payment Date",
        "value": "2021-10-23"
      },
      {
        "name": "URL",
        "value": "https://cp.tatapower.com:4443/inv?inv_nou003dMDkzMzc3MTg2MTQy"
      }
    ]
  }
}
Sign up to request clarification or add additional context in comments.

Comments

1

its invalid JSON, remove " from before and after of '{','[','}',']'

string aaaa = 
              "{" +
                "\"respCode\":\"1\",\"status\":\"SUCCESS\",\"response\":" +
                "{" +
                "\"chId\":1,\"refId\":\"YBL4ABC0D3D61A349F18605928DD63E8886\",\"approvalRefNum\":\"264992511\",\"responseCode\":\"000\",\"responseReason\":\"Successful\",\"complianceReason\":\"\",\"complianceRespCd\":\"\",\"billDetails\":" +
                    "[" +
                        "{\"name\":\"Consumer Number\",\"value\":\"900001073788\"}" +
                    "]," +
                    "\"billerResponse\":" +
                        "{" +
                            "\"customerName\":\"MNTALI\",\"amount\":\"421\",\"dueDate\":\"2021-11-06\",\"custConvFee\":\"\",\"custConvDesc\":\"\",\"billDate\":\"2021-10-16\",\"billNumber\":\"9337718556142\",\"billPeriod\":\"MONTHLY\",\"billTags\":" +
                            "[" +
                                "{\"name\":\"Early Payment Amount\",\"value\":\"41200\"}" +
                            "]" +
                        "}" +
                    ",\"additionalInfo\":" +
                    "[" +
                        "{\"name\":\"Early Payment Date\",\"value\":\"2021-10-23\"}," +
                        "{\"name\":\"URL\",\"value\":\"https://cp.tatapower.com:4443/inv?inv_nou003dMDkzMzc3MTg2MTQy\"}" +
                    "]" +
                  "}" +
                "}";

var userObj1 = JObject.Parse(aaaa);

its work for me

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.