Appending key,value pair to my JSON data
This is my JSON response
{
"PatientSearchResult": {
"Patient": [{
"AccountBalanceCalcMethod": 2,
"AlternatePatientID": 0,
"AssignmentOfBenifits": 0,
"CellPhoneNumber1": null,
"CellPhoneNumber2": null,
"Citizenship": 0,
"Credential": 0,
"DateOfBirth": null,
"Deceased": 0,
"DeceasedDate": "\/Date(-62135578800000-0500)\/",
"DoesPatientHaveResidentProof": false,
"DriversLicenseNumber": null,
"DriversLicenseState": 0,
"EmailAddress1": null,
"EmailAddress2": null,
"Enabled": false,
"Ethnicity": 0,
"Firstname": "2914 FirstName"
}, {
"AccountBalanceCalcMethod": 2,
"AlternatePatientID": 0,
"AssignmentOfBenifits": 0,
"CellPhoneNumber1": null,
"CellPhoneNumber2": null,
"Citizenship": 0,
"Credential": 0,
"DateOfBirth": "\/Date(378709200000-0500)\/",
"Deceased": 0,
"DeceasedDate": "\/Date(-62135578800000-0500)\/",
"DoesPatientHaveResidentProof": false,
"DriversLicenseNumber": null,
"DriversLicenseState": 0,
"EmailAddress1": null,
"EmailAddress2": null,
"Enabled": false,
"Ethnicity": 0,
"Firstname": "4261 FirstName"
}, {
"AccountBalanceCalcMethod": 2,
"AlternatePatientID": 0,
"AssignmentOfBenifits": 0,
"CellPhoneNumber1": null,
"CellPhoneNumber2": null,
"Citizenship": 0,
"Credential": 0,
"DateOfBirth": "\/Date(1136264400000-0500)\/",
"Deceased": 0,
"DeceasedDate": "\/Date(-62135578800000-0500)\/",
"DoesPatientHaveResidentProof": false,
"DriversLicenseNumber": null,
"DriversLicenseState": 0,
"EmailAddress1": null,
"EmailAddress2": null,
"Enabled": false,
"Ethnicity": 0,
"Firstname": "Bo"
}, {
"AccountBalanceCalcMethod": 2,
"AlternatePatientID": 0,
"AssignmentOfBenifits": 0,
"CellPhoneNumber1": null,
"CellPhoneNumber2": null,
"Citizenship": 0,
"Credential": 0,
"DateOfBirth": "\/Date(-2192126400000-0400)\/",
"Deceased": 0,
"DeceasedDate": "\/Date(-62135578800000-0500)\/",
"DoesPatientHaveResidentProof": false,
"DriversLicenseNumber": null,
"DriversLicenseState": 0,
"EmailAddress1": null,
"EmailAddress2": null,
"Enabled": false,
"Ethnicity": 0,
"Firstname": "Mark"
}, {
"AccountBalanceCalcMethod": 2,
"AlternatePatientID": 0,
"AssignmentOfBenifits": 0,
"CellPhoneNumber1": null,
"CellPhoneNumber2": null,
"Citizenship": 0,
"Credential": 0,
"DateOfBirth": "\/Date(-381697200000-0500)\/",
"Deceased": 0,
"DeceasedDate": "\/Date(-62135578800000-0500)\/",
"DoesPatientHaveResidentProof": false,
"DriversLicenseNumber": null,
"DriversLicenseState": 0,
"EmailAddress1": null,
"EmailAddress2": null,
"Enabled": false,
"Ethnicity": 0,
"Firstname": "Scott"
}, {
"AccountBalanceCalcMethod": 2,
"AlternatePatientID": 0,
"AssignmentOfBenifits": 0,
"CellPhoneNumber1": null,
"CellPhoneNumber2": null,
"Citizenship": 0,
"Credential": 0,
"DateOfBirth": "\/Date(-445806000000-0500)\/",
"Deceased": 0,
"DeceasedDate": "\/Date(-62135578800000-0500)\/",
"DoesPatientHaveResidentProof": false,
"DriversLicenseNumber": null,
"DriversLicenseState": 0,
"EmailAddress1": null,
"EmailAddress2": null,
"Enabled": false,
"Ethnicity": 0,
"Firstname": "John"
}, {
"AccountBalanceCalcMethod": 2,
"AlternatePatientID": 0,
"AssignmentOfBenifits": 0,
"CellPhoneNumber1": null,
"CellPhoneNumber2": null,
"Citizenship": 0,
"Credential": 0,
"DateOfBirth": "\/Date(-880830000000-0500)\/",
"Deceased": 0,
"DeceasedDate": "\/Date(-62135578800000-0500)\/",
"DoesPatientHaveResidentProof": false,
"DriversLicenseNumber": null,
"DriversLicenseState": 0,
"EmailAddress1": null,
"EmailAddress2": null,
"Enabled": false,
"Ethnicity": 0,
"Firstname": "Dagwood"
}, {
"AccountBalanceCalcMethod": 2,
"AlternatePatientID": 0,
"AssignmentOfBenifits": 0,
"CellPhoneNumber1": null,
"CellPhoneNumber2": null,
"Citizenship": 0,
"Credential": 0,
"DateOfBirth": null,
"Deceased": 0,
"DeceasedDate": "\/Date(-62135578800000-0500)\/",
"DoesPatientHaveResidentProof": false,
"DriversLicenseNumber": null,
"DriversLicenseState": 0,
"EmailAddress1": null,
"EmailAddress2": null,
"Enabled": false,
"Ethnicity": 0,
"Firstname": "Clyde"
}, {
"AccountBalanceCalcMethod": 2,
"AlternatePatientID": 0,
"AssignmentOfBenifits": 0,
"CellPhoneNumber1": null,
"CellPhoneNumber2": null,
"Citizenship": 0,
"Credential": 0,
"DateOfBirth": "\/Date(-249678000000-0500)\/",
"Deceased": 0,
"DeceasedDate": "\/Date(-62135578800000-0500)\/",
"DoesPatientHaveResidentProof": false,
"DriversLicenseNumber": null,
"DriversLicenseState": 0,
"EmailAddress1": null,
"EmailAddress2": null,
"Enabled": false,
"Ethnicity": 0,
"Firstname": "Fred"
}]
}
}
I am trying to parse it like this.
function SortByName(x,y) {
return ((x.LastName == y.LastName) ?
0 : ((x.LastName > y.LastName) ? 1 : -1 ));
}
function RenderPatientSearchData(PatientSearchResponse){
var PatientSearchData = JSON.parse(PatientSearchResponse);
var results = PatientSearchData['PatientSearchResult'];
results.Patient.sort(SortByName);
for (i = 0, len = results.PatientSearchResult.Patient.length; i < len; i++) {
// some code here
}
//....
}
How can i append key,valu开发者_运维知识库e pair to my JSON. I want to append
Header:'somevalue'
how would i append a Header label to first items of each data. some like which will make me differentiate that these are A Names , these are B Names...
You can see a sample response of the data in this link... something like this
https://github.com/appcelerator/KitchenSink/raw/master/Resources/examples/table_view_headers.js
It's pretty simple if you want to add properties to a Javascript object (as opposed to manipulating a JSON string). Wherever you want to add 'Header': 'somevalue' just do:
PatientSearchData.Header = 'somevalue';
精彩评论