none
how to Deserialization JSON string RRS feed

  • Question

  • Hi,

    I want to Deserialization following script. pls guide

    [{"ItemId":12,"WebId":"90dccaf8-d160-4d7e-a269-03ffbda58126","ListId":"183f123c-4a66-422b-871c-5117c65e2221"}]

    i want to get Itemid value.

    thx


    iffi


    • Edited by imughal Wednesday, March 1, 2017 12:50 PM
    Wednesday, March 1, 2017 12:48 PM

All replies

  • Hi imughal,

    You can use Newton Json.NET to deserialize the Json array object, please refer the demo below:

    JSON Serialization And Deserialization In C#

    Deserialize an Object

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, March 2, 2017 4:35 AM
  • The following script will convert your JSON into a PowerShell Custom object and output the number 12.  

    1. Launch Powershell ISE
    2. Paste this script into the script pane and run it.
    3. It will output the # 12.

    #Add JSON to a variable
    $JSON = @'
    [{"ItemId":12,"WebId":"90dccaf8-d160-4d7e-a269-03ffbda58126","ListId":"183f123c-4a66-422b-871c-5117c65e2221"}]
    '@
    #Convert the JSON into a PSCustomObject
    $JSONResults = $JSON | ConvertFrom-Json

    #Output the ItemId
    $JSONResults.ItemId

    Please mark the question as answered if you don't have any further questions on this topic.

     


    Thanks, Trey

    Thursday, March 2, 2017 4:57 AM
  • Hi,

    Please try below code block. It may help you.

    var jsonObj = [{"ItemId":12,"WebId":"90dccaf8-d160-4d7e-a269-03ffbda58126","ListId":"183f123c-4a66-422b-871c-5117c65e2221"}];
    var jsonObjAsJSON = JSON.stringify(jsonObj);
    var deserializedObj = JSON.parse(jsonObjAsJSON);
    alert(deserializedObj[0].ItemId)

    Regards.

    Thursday, March 2, 2017 5:52 AM