I'm attempting to search through this json for a specific value.
I would like to search by the State value, such as 'NH' and get back the MaintenancePercentage and OfficePercentage.
I've tried looping through payrollDefaults.State and I'm getting back nothing.
var payrollDefaults =
[
{
"State": "NH",
"MaintenancePercentage": 21.45,
"OfficePercentage": 22.56
},
{
"State": "NC",
"MaintenancePercentage": 21.79,
"OfficePercentage": 22.41
},
{
"State": "OH",
"MaintenancePercentage": 21.33,
"OfficePercentage": 22.25
},
{
"State": "RI",
"MaintenancePercentage": 23.04,
"OfficePercentage": 23.22
},
{
"State": "SC",
"MaintenancePercentage": 21.31,
"OfficePercentage": 31.33
},
{
"State": "TX",
"MaintenancePercentage": 35.6,
"OfficePercentage": 24.48
},
{
"State": "VA",
"MaintenancePercentage": 32.32,
"OfficePercentage": 30.47
},
{
"State": "AL",
"MaintenancePercentage": 13.33,
"OfficePercentage": 12.42
},
{
"State": "CA",
"MaintenancePercentage": 49.37,
"OfficePercentage": 59.67
},
{
"State": "FL",
"MaintenancePercentage": 34.62,
"OfficePercentage": 31.06
},
{
"State": "GA",
"MaintenancePercentage": 35.55,
"OfficePercentage": 30.29
},
{
"State": "IN",
"MaintenancePercentage": 33.45,
"OfficePercentage": 30.69
},
{
"State": "MA",
"MaintenancePercentage": 32.9,
"OfficePercentage": 29.34
},
{
"State": "MI",
"MaintenancePercentage": 34.95,
"OfficePercentage": 29.46
},
{
"State": "MT",
"MaintenancePercentage": 35.91,
"OfficePercentage": 30.02
}
]
EDIT:
I ended up converting this from a string to JSON.
var json = $.parseJSON(payrollDefaults);