SPXmlToJson - wrapping the returned Title with a custom URL containing the item ID within the JSON

Jan 31, 2013 at 8:56 PM
I have a list with items in it that I am querying with a SPXmlToJson call. I am trying to wrap the Item Title in the returned JSON within a link to a custom page and am not sure exactly what the best way to implement it is. The call is:
    var x = $(xData.responseXML).SPFilterNode("z:row").SPXmlToJson({
        mapping: {
            ows_Created: {mappedCreated: "Created", objectType: "Text"},
            ows_LinkTitle: {mappedLinkedTitle: "LinkedTitle", objectType: "Text"},
            ows_Title: {mappedTitle: "Title", objectType: "Text"},
            ows_ID: {mappedID: "ID", objectType: "Counter"}
        },
        includeAllAttrs: false,
        removeOws: true
    });
I have tried various combinations on adjusting the line
ows_Title: {mappedTitle: "Title", objectType: "Text"},
without success. Does anybody have any suggestions?
Coordinator
Jan 31, 2013 at 10:06 PM
Alan:

This should do it:
    var x = $(xData.responseXML).SPFilterNode("z:row").SPXmlToJson({
        mapping: {
            ows_Created: {mappedName: "Created", objectType: "Text"},
            ows_LinkTitle: {mappedName: "LinkedTitle", objectType: "Text"},
            ows_Title: {mappedName: "Title", objectType: "Text"},
            ows_ID: {mappedName: "ID", objectType: "Counter"}
        },
        includeAllAttrs: false,
        removeOws: true
    });
You had renamed all of the mappedName attributes.

M.
Feb 1, 2013 at 4:23 PM
Edited Feb 1, 2013 at 4:25 PM
Oops :) thanks!
So what would be the best way to wrap a link around the "Title"?
Coordinator
Feb 1, 2013 at 5:11 PM
SPXmlToJson is just going to convert the data returned from the call from XML to JSON. Then you need to do something with it.

In most cases, I just parse the XML directly. The exanmples on the GetListItems documentation page ought to help.

M.