grep or each a response to push
I have a REST service that returns the following JSON format:
-
{"Message":"GetShapeContacts","PageNumber":1,"PageSize":10,"Status":1,"TotalObjects":18,"TotalPages":2,"Data":[{"__type":"ShapeContactDto","Contactguid":"C06F98579D3642498925991D1E728724","Shcguid":"FD0FC9945D8B4D6996C189F314E6AE9E","Shpguid":"74BA57F6D8A24E56976BBB9E411A1056","Contactrole":""},{"__type":"ShapeContactDto","Contactguid":"C06F98579D3642498925991D1E728724","Shcguid":"77325672FDC24D1C81B5DCBE8C014596","Shpguid":"74BA57F6D8A24E56976BBB9E411A1056","Contactrole":""},{"__type":"ShapeContactDto","Contactguid":"C06F98579D3642498925991D1E728724","Shcguid":"9AB91CCCFF664FA3A5ADDF222F1604F6","Shpguid":"74BA57F6D8A24E56976BBB9E411A1056","Contactrole":""},{"__type":"ShapeContactDto","Contactguid":"49C65EF0F0D04DC5AADB51E4F9B61456","Shcguid":"41A5E2394D7D4D0180DF403769494C4B","Shpguid":"74BA57F6D8A24E56976BBB9E411A1056","Contactrole":""},{"__type":"ShapeContactDto","Contactguid":"A631EBF55F1341F2AEFC786F57252CC0","Shcguid":"C5C9D119C4504B20BB71D833EAE0B778","Shpguid":"74BA57F6D8A24E56976BBB9E411A1056","Contactrole":""},{"__type":"ShapeContactDto","Contactguid":"A631EBF55F1341F2AEFC786F57252CC0","Shcguid":"89D72E776D5840BE84E894D3A1F6E73B","Shpguid":"74BA57F6D8A24E56976BBB9E411A1056","Contactrole":""},{"__type":"ShapeContactDto","Contactguid":"C06F98579D3642498925991D1E728724","Shcguid":"6C2390220A6E438499D8C920A0ECA279","Shpguid":"74BA57F6D8A24E56976BBB9E411A1056","Contactrole":""},{"__type":"ShapeContactDto","Contactguid":"8B065FD553664C7DBBE6F563A430AF97","Shcguid":"A00730930CFE458B8844A0E9FB87A2B6","Shpguid":"74BA57F6D8A24E56976BBB9E411A1056","Contactrole":""},{"__type":"ShapeContactDto","Contactguid":"8B065FD553664C7DBBE6F563A430AF97","Shcguid":"744F9EB7A131451F98AD16FA251A82F8","Shpguid":"74BA57F6D8A24E56976BBB9E411A1056","Contactrole":""},{"__type":"ShapeContactDto","Contactguid":"C06F98579D3642498925991D1E728724","Shcguid":"DB5D982FB2E0430691BC9578BB5C4F09","Shpguid":"74BA57F6D8A24E56976BBB9E411A1056","Contactrole":""}]}
What i want to do after this is return is to create a string array of just the Contactguid values so i can submit those to another service.
how can i do that?
I took a stab at it and got the following:
-
$.ajax({
type: "GET",
cache: false,
data: reqData,
url: "http://demo.com/Service/Contacts.svc/GetContacts",
contentType: "application/json",
dataType: "json",
success: function(xml) {
_shapeContactSet = xml.Data;
_shapeContacts = jQuery.grep(_shapeContactSet, function(n, i) {
return (n.__type == "ShapeContactDto");
});
_contactGuidSet = [];
//need to push just the ContactGuid, nothing else
jQuery.each(_shapeContacts, function(i, val) {
_contactGuidSet.push(val);
});
if (_contactGuidSet.length == 0) {
_processContactResponse();
}
Any suggestions?