Reputation: 9
"email": "FamilyMembers: 54; Children: 4; Income: 8484; Literacy: UG; MaritalStatus: Married;
I am Trying this code
if (arr.email != undefined) {
out += "Family Members:" + arr.email.FamilyMembers + "<br/>Children:" + arr.email.Children + "<br/>Income:" + arr.email.Income + "<br/>Literacy:" + arr.email.Literacy + "<br/>Marital Status:" + arr.email.MaritalStatus;
}
Upvotes: 0
Views: 55
Reputation: 6562
parse it, for example :
var myString = arr.email;
var arrayOfKV = myString.split(";");
var obj = {};
while( elem = arrayOfKV.shift() ) {
var kV = elem.split(":");
obj[k] = V;
}
var properJSON = JSON.stringify({ email: obj });
Upvotes: 0
Reputation: 1980
Following code will be enough.
var p = {"email": "FamilyMembers: 54; Children: 4; Income: 8484; Literacy: UG; MaritalStatus: Married;"}
for (var key in p) {
if (key == email) {
var emailElt = p[key]
for (var subKey in emailElt) {
if (p.hasOwnProperty(subKey)) {
alert(subKey + " -> " + emailElt[subKey]);
}
}
}
}
Upvotes: 0
Reputation: 1345
Your JSON seems to be improperly formatted. If you do want to access the sub-elements of email as objects, your JSON should look like this:
{ "email" : { "FamilyMembers": 54,
"Children": 4,
"Income": 8484,
"Literacy": "UG",
"MaritalStatus": "Married"
}
}
Upvotes: 1