在针对ShowOpenDialg
方法的Javascript中,我收到以下回复:
"{"items":[{"id":"{168B874F-9CF7-E311-B136-00155D02101E}","name":"Test Account1 - 6/19/2014","html":"<nobr title=\"Test Account1 - 6/19/2014\" class=\"gridcellpadding\"><a href=\"#\" id=\"gridBodyTable_primaryField_{168B874F-9CF7-E311-B136-00155D02101E}_0\" target=\"_self\" title=\"Test Account1 - 6/19/2014\" class=\"ms-crm-List-Link\" tabindex=\"6\">Test Account1 - 6/19/2014</a></nobr>","type":"1","values":" [{\"name\":\"name\",\"value\":\"Test Account1 - 6/19/2014\"}, {\"name\":\"accountnumber\",\"value\":\"\"},{\"name\":\"primarycontactid\",\"value\":\"\"}, {\"name\":\"address1_city\",\"value\":\"\"},{\"name\":\"telephone1\",\"value\":\"\"}, {\"name\":\"emailaddress1\",\"value\":\"\"},{\"name\":\"fax\",\"value\":\"\"}, {\"name\":\"address1_name\",\"value\":\"\"}, {\"name\":\"address1_fax\",\"value\":\"\"}]","keyValues":"{\"name\": {\"name\":\"name\",\"value\":\"Test Account1 - 6/19/2014\"},\"accountnumber\": {\"name\":\"accountnumber\",\"value\":\"\"},\"primarycontactid\": {\"name\":\"primarycontactid\",\"value\":\"\"},\"address1_city\": {\"name\":\"address1_city\",\"value\":\"\"},\"telephone1\": {\"name\":\"telephone1\",\"value\":\"\"},\"emailaddress1\": {\"name\":\"emailaddress1\",\"value\":\"\"},\"fax\": {\"name\":\"fax\",\"value\":\"\"},\"address1_name\": {\"name\":\"address1_name\",\"value\":\"\"},\"address1_fax\": {\"name\":\"address1_fax\",\"value\":\"\"}}","category":null,"ambiguousRecordsXml":null,"sel ected":false,"displayclass":"","onclick":"openlui(new Sys.UI.DomEvent(event));"}]}"
我需要在第一行回复中检索id
和name
。
如何在JS中做到这一点?检索方法应该是通用的,因为响应可能包含多个记录。这是单一记录的数据。
感谢。
答案 0 :(得分:1)
我设法提取价值如下:
obj = JSON.parse(dlgReturnValue); //dlgReturnValue is JSON object holds the result
var id = obj.items[0].id;
var name = obj.items[0].name;