Harshitha C
Harshitha C

Reputation: 75

Can't get field value from parsed JSON

This is my Ajax call ,

  let options = {};
  options.chaincodeId = "instrumentcc";
  options.methodToBeCalled = "queryInstrument";
  let arguments = {};
  arguments.arg1 = '{"selector":{"Status":"open"}}';
  options.dataArguments = arguments;
  console.log("options ", options)
  $.ajax({
    url: "http://localhost:3000/postSender",
    datatype: "JSON",
    type: "Post",
    data: options,
    success: function (data) {
      console.log("data ", data)
      data1 = JSON.parse(data);
      console.log("data parse", data1)
      } 
  });

Response Data is

[{"Key":"1088b94e1f5353484ff9609cbeef8cd36679e1af145e273140c65d96a7e24b07",
  "Record":{
            "docType":"InstruObject",
            "RefNo":"I001",
            "Date":"2018-11-15T00:00:00Z",
            "SellerID":"B002",
            "BuyerID":"B001",
            "Amount":"1000",
            "Status":"open",
            "DueDate":"2019-11-16T00:00:00Z",
            "ProgramID":"1prg",
            "PPRID":"1ppr",
            "UploadBatchNo":"323453454121",
            "ValueDate":"2019-01-04T12:43:59Z"
          }
}]

I need to get the RefNo from Record . I used data1.Record.RefNo , it show data1.Record is undefined. How can I access RefNo then?? Thanks in advance.

Upvotes: 0

Views: 84

Answers (1)

Abhishek
Abhishek

Reputation: 380

Use console.log(data[0].Record.RefNo); without JSON.parse.

Upvotes: 0

Related Questions