简体   繁体   中英

json api response data fields

how can you properly use data fields in javascript? I dont know how to drill down to them... for example i can use data, but i can't use the TaskName that is underneath data. Please help thank you.

If I parse the response like this: var data = JSON.parse(responseBody);

how do i get to a field like TaskName?? Usually I would try something like data.TaskName === "003021919913"; but that is not working.

{
  "Data": {
    "QRCode_ID": 168,
    "Repairer_ID": null,
    "AssignedToEmployee_ID": null,
    "TaskName": "003021919913",
    "DueDate": "2015-07-02T00:12:53.597",
    "DueDateTimeSpan": 1959471956224,
    "TaskStatus_ID": 1,
    "Description": "due 6/30, 5:00",
    "TaskUrgency_ID": null,
    "TaskType_ID": null,
    "DueDateDisplay": "2015-07-02 00:12",.......
      }
  },
  "Messages": [
    "success"
  ]
}

Udated answer:

You should be able to access "TaskName" via data.Data.TaskName .

In this case your library is storing your JSON object into a var data . this variable becomes a reference to the object, inside of the object it has a property Data which holds the property that you want to use, which you can access w/ dot syntax.

Now, something else that might hook you up. In your test, you want to make sure your testing TaskName against the String value of 003021919913 in this case, if you're testing it against the number, you'll need to do something like:

var taskNameTest = parseInt(data.Data.TaskName);
assert(taskNameTest).equal(003021919913); //not sure what assertion library you're using.

hopefully that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM