简体   繁体   中英

How to retrieve a json object from a sharepoint list

I am created myself a custom list with sharepoint 2007, which is exactly the same as any excel spreadsheet in effect.

I was told that i can get this out all of the information as a json or XML object. I don't have access to the file system, only to sharepoint web interface.

Can i just use a url and do my normal getJson ?

    $.getJSON("http://somesharepointurl.asp?get=json",function(results){
        console.info(results);
        $.each(results, function(){

        });
    });

Or is there no way of doing this without writing some backend service?

Edit

https://someserver/sites/DisasterRecovery/eventmgmt/DRR/_vti_bin/owssvr.dll?Cmd=Display&List={B0ACA997-8A41-498B-97FE-B276D48F64D7}&XMLDATA=TRUE

I have tried this... it gave me this:

HTTP/1.1 200 OK
Server: Microsoft-IIS/7.5
Date: Fri, 14 Dec 2012 11:41:55 GMT
Connection: close

No idea what to look for whatsoever i'm afraid :(

  1. SharePoint 2007 doesn't provide you with JSON formatted results, only SOAP/XML web services and the URL Protocol you refer to in the update
  2. Make sure you append the /_vti_bin part to the address of the correct subsite, rather than the library (although if you made this error, you'd get 404)

Found the simple answer:

jquery.SPServices

you will need jQuery 1.4.2+ to run this but its fantastic :) It has many more method's than just getting XML or json back.

 var query = "<Query><OrderBy><FieldRef Name='Created' Ascending='False' /></OrderBy</Query>";
 $().SPServices({
     operation:"GetListItems",
     async:false,
     listName:"Home Page Carousel",
     CAMLViewFields:"<ViewFields><FieldRef Name='userName'/><FieldRef Name='userDepartment'/><FieldRef Name='message'/></ViewFields>",
     CAMLQuery:query,
     CAMLRowLimit:10,
     completefunc:function (xData, Status) {
     console.info(xData);
     console.info(Status);
         $(xData.responseXML).SPFilterNode("z:row").each(function () {
             var $this = $(this);
             $this.attr("ows_message")//retrieve list data here and do stuff here
         });
     }
 });

This will return you a lovely chunk of XML .

另一种选择,在 sharepoint 2010 中尝试使用这样的 OData: http://webname/_vti_bin/ListData.svc/listname ,过滤和排序的功能与标准 OData 相同,参考可以在这里找到: http:// www.odata.org/documentation

尝试在 URL 查询字符串中添加 &Query=*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM