sandrooco
sandrooco

Reputation: 8716

Sharepoint 2013: accessing data from People Picker inputs (JSON)

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="
[{&quot;Key&quot;:&quot;i:0#.w|XXXXX\\tkabcs&quot;,&quot;Description&quot;
:&quot;XXXXX\\tkabcs&quot;,&quot;DisplayText&quot;
:&quot;ABCDE, ABC-DEF&quot;,&quot;EntityType&quot;:&quot;User&quot;
,&quot;ProviderDisplayName&quot;:&quot;Active Directory&quot;,&quot;ProviderName&quot;:&quot;AD&quot;,&quot;IsResolved&quot;
    :true,&quot;EntityData&quot;:,&quot;MultipleMatches&quot;:}]">

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

Answers (1)

devlin carnate
devlin carnate

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&quot;:,&quot;MultipleMatches&quot;:}]

to:

EntityData&quot;:&quot;MultipleMatches&quot;}]

(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

Related Questions