如何解析来自Service的JSON数据

时间:2016-10-14 12:53:35

标签: javascript angularjs

"{items:[{"$param":"PostCode","$value":["560059"],"type":"String","mode":"IN"},{"$param":"Address1stLine","$value":["Bangalore"],"type":"String","mode":"IN"},{"$param":"LastName","$value":["Ingale"],"type":"String","mode":"IN"},{"$param":"mail_To","$value":["atul.ingale@mindtree.com"],"type":"String","mode":"IN"},{"$param":"Gender","$value":["Male"],"type":"String","mode":"IN"},{"$param":"Complaint","$value":[""],"type":"String","mode":"IN"},{"$param":"Forename","$value":["Atul"],"type":"String","mode":"IN"},{"$param":"XRayComments","$value":[""],"type":"String","mode":"INOUT"},{"$param":"BloodTestComments","$value":[""],"type":"String","mode":"INOUT"},{"$param":"NeedBloodTest","$value":["false"],"type":"Boolean","mode":"INOUT"},{"$param":"NeedXRay","$value":["false"],"type":"Boolean","mode":"INOUT"}]}"

如何解析来自REST服务响应的上述数据,包括Javascript和angularjs

2 个答案:

答案 0 :(得分:0)

Angularjs:

var yourData = angular.fromJson(yourJsontext)

JavaScript的:

var yourData = JSON.parse(yourJsontext)

答案 1 :(得分:-1)

如果您正在使用角度,请使用它:

angular.toJson(yourobj, pretty);