More in this section

Forums / Developing with Sitefinity / Deserializing the response from the PagesService

Deserializing the response from the PagesService

2 posts, 0 answered
  1. Travis
    Travis avatar
    86 posts
    Registered:
    15 Oct 2008
    09 May 2012
    Link to this post
    Hello,
    I'm trying to migrate some of the data from one Sitefinity Installation to another, and thought I could use a simple serialization process to do this. I figured that all the data was available from the PagesService, in JSON or XML, so, I figured it should not be too much of a problem.

    However, I must be doing something wrong because I can't seem to get items to deserialize properly. I've brought my JSON string into .NET, and I'm attempting to deserialize it in the following way:

    string json = "{\"Context\":null,\"IsGeneric\":false,\"Items\":[{\"AdditionalUrlsRedirectToDefaultOne\":true,\"AllowMultipleUrls\":false,\"AllowParameterValidation\":true,\"AvailableLanguages\":[],\"FullUrl\":\"/FYiSitefinity/contact-us\",\"HasChildren\":false,\"HasTranslationSiblings\":false,\"Id\":\"90ce64c4-0eb8-4f32-980d-06ecddd67466\",\"IsExternal\":false,\"LinkedNodeFullUrl\":null,\"LinkedNodeId\":\"00000000-0000-0000-0000-000000000000\",\"LinkedNodeProvider\":null,\"LinkedNodeTitle\":null,\"LocalizationStrategy\":0,\"MultipleNavigationNodes\":null,\"NodeType\":0,\"OpenNewWindow\":false,\"ParentId\":\"f669d9a7-009d-4d83-ddaa-000000000002\",\"Path\":\"contact-us\",\"RedirectUrl\":null,\"Title\":{\"PersistedValue\":\"Contact Us\",\"Value\":\"Contact Us\",\"ValuesPerCulture\":[{\"Key\":\"\",\"Value\":\"Contact Us\"}]},\"TitlesPath\":\"Contact Us\",\"CurrentTemplateId\":\"00000000-0000-0000-0000-000000000000\",\"DateCreated\":\"/Date(1335981795987)/\",\"IsContentEditable\":true,\"IsEditable\":true,\"IsGroup\":false,\"IsHomePage\":false,\"IsSubPageCreationAllowed\":true,\"LevelOrdinal\":5,\"Location\":\" <span class='sfSep'>|</span> on <strong>top level</strong>\",\"Owner\":\"Ernest Ariola\",\"PageDataId\":\"c34ef83d-85a4-4ec8-b173-c9d58f9705d1\",\"PageEditUrl\":\"/FYiSitefinity/contact-us/Action/Edit\",\"PageLifecycleStatus\":{\"ErrorMessage\":null,\"IsAdmin\":true,\"IsLocked\":false,\"IsLockedByMe\":false,\"IsPublished\":true,\"LastModified\":\"/Date(1336491333040)/\",\"LastModifiedBy\":null,\"LockedByUsername\":\"\",\"LockedSince\":null,\"Message\":null,\"PublicationDate\":\"/Date(1335981795717)/\",\"SupportsContentLifecycle\":true,\"WorkflowStatus\":null},\"PageLiveUrl\":\"http://localhost:53288/FYiSitefinity/contact-us\",\"PageLocation\":null,\"PageViewUrl\":\"/FYiSitefinity/contact-us\",\"Status\":\"Published\",\"StatusText\":\"Published\",\"Template\":null,\"UrlName\":\"contact-us\",\"VersioningId\":\"c34ef83d-85a4-4ec8-b173-c9d58f9705d1\",\"Visible\":true,\"WorkflowOperations\":null}],\"TotalCount\":1}";
             
            string json3 = "{\"AdditionalUrlsRedirectToDefaultOne\":true,\"AllowMultipleUrls\":false,\"AllowParameterValidation\":true,\"AvailableLanguages\":[],\"FullUrl\":\"/FYiSitefinity/contact-us\",\"HasChildren\":false,\"HasTranslationSiblings\":false,\"Id\":\"90ce64c4-0eb8-4f32-980d-06ecddd67466\",\"IsExternal\":false,\"LinkedNodeFullUrl\":null,\"LinkedNodeId\":\"00000000-0000-0000-0000-000000000000\",\"LinkedNodeProvider\":null,\"LinkedNodeTitle\":null,\"LocalizationStrategy\":0,\"MultipleNavigationNodes\":null,\"NodeType\":0,\"OpenNewWindow\":false,\"ParentId\":\"f669d9a7-009d-4d83-ddaa-000000000002\",\"Path\":\"contact-us\",\"RedirectUrl\":null,\"Title\":{\"PersistedValue\":\"Contact Us\",\"Value\":\"Contact Us\",\"ValuesPerCulture\":[{\"Key\":\"\",\"Value\":\"Contact Us\"}]},\"TitlesPath\":\"Contact Us\",\"CurrentTemplateId\":\"00000000-0000-0000-0000-000000000000\",\"DateCreated\":\"/Date(1335981795987)/\",\"IsContentEditable\":true,\"IsEditable\":true,\"IsGroup\":false,\"IsHomePage\":false,\"IsSubPageCreationAllowed\":true,\"LevelOrdinal\":5,\"Location\":\" <span class='sfSep'>|</span> on <strong>top level</strong>\",\"Owner\":\"Ernest Ariola\",\"PageDataId\":\"c34ef83d-85a4-4ec8-b173-c9d58f9705d1\",\"PageEditUrl\":\"/FYiSitefinity/contact-us/Action/Edit\",\"PageLifecycleStatus\":{\"ErrorMessage\":null,\"IsAdmin\":true,\"IsLocked\":false,\"IsLockedByMe\":false,\"IsPublished\":true,\"LastModified\":\"/Date(1336491333040)/\",\"LastModifiedBy\":null,\"LockedByUsername\":\"\",\"LockedSince\":null,\"Message\":null,\"PublicationDate\":\"/Date(1335981795717)/\",\"SupportsContentLifecycle\":true,\"WorkflowStatus\":null},\"PageLiveUrl\":\"http://localhost:53288/FYiSitefinity/contact-us\",\"PageLocation\":null,\"PageViewUrl\":\"/FYiSitefinity/contact-us\",\"Status\":\"Published\",\"StatusText\":\"Published\",\"Template\":null,\"UrlName\":\"contact-us\",\"VersioningId\":\"c34ef83d-85a4-4ec8-b173-c9d58f9705d1\",\"Visible\":true,\"WorkflowOperations\":null}";
     
    var objJson = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Telerik.Sitefinity.Pages.Model.PageNode>(json);
    var objJson3 = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Telerik.Sitefinity.Pages.Model.PageNode>(json3);

    The first string, json, contains the full output from the response (with most of the items removed, to shorten it up). The second string, json3, contains the first of those items. objJson deserializes to an object of type Telerik.Sitefinity.Pages.Model.PageNode, but few of properties are correct (it looks to be a new instance of a pagenode). objJson3 doesn't get a value, since the deserializer crashes when attempting that deserialization with an exception stating that there is invalid LString data. Using the built in javascript serialization methods, it crahses for json3, stating that the first datetime passed is invalid, however when passing json, it doesn't crash, instead, it deserializes my object, albeit not correctly, as described above.

    What do I have to do to properly deserialize the output of the PagesService to objects?

    edit My example above shows that i'm using the built in JS deserializer, as opposed to the NewtonSoft JsonConvert method of doing it. Trust that I've tried both that the results are as described above.
  2. Travis
    Travis avatar
    86 posts
    Registered:
    15 Oct 2008
    11 May 2012
    Link to this post
    Does anyone have any suggestions as to how to deserialize this data?
2 posts, 0 answered