Reputation: 8716
I have a Sharepoint 2013 client people picker. It returns the following structure:
<input id="peoplePickerDiv1_TopSpan_HiddenInput" name="peoplePickerDiv1_TopSpan_HiddenInput" type="hidden" value="
[{"Key":"i:0#.w|XXXXX\\tkabcs","Description"
:"XXXXX\\tkabcs","DisplayText"
:"ABCDE, ABC-DEF","EntityType":"User"
,"ProviderDisplayName":"Active Directory","ProviderName":"AD","IsResolved"
:true,"EntityData":,"MultipleMatches":}]">
How can I access stuff like the "Key" in the value attribute?
(Sorry for the bad structure, had to take it from a console log)
Upvotes: 0
Views: 976
Reputation: 8592
That input's value looks like JSON, except it has two syntax errors near the end of the string. I had to change:
EntityData":,"MultipleMatches":}]
to:
EntityData":"MultipleMatches"}]
(removing an extra , and : )
With those changes, I was able to parse the string to an object and access the Key.
var valJson = $('#peoplePickerDiv1_TopSpan_HiddenInput').val();
var parsed = $.parseJSON(valJson);
console.log(parsed[0].Key);
Here is a JSFiddle demo.
Upvotes: 2