how to parse json result from sharepoint to show list names

This is the first time I work with JSon, so pls dont be rude with me :)

I have this website. http://msdn.microsoft.com/en-us/library/jj164022(v=office.15).aspx

and this javascript sample:

jQuery.ajax({
url: http:// site url/_api/web/lists,
type: "GET",
headers: {
"ACCEPT","application/json;odata=verbose",
"Authorization", "Bearer " + accessToken
},
})

The thing is I have a div called results and I would like to show the list names that the rest service returns me.

Answers


It's hard to say exactly how to show the list in your div without knowing how the returned JSON is formatted. But the main idea is that you'll need to add a success callback function to your jQuery.ajax() call in which you parse the returned data and insert it into your div. For example:

jQuery.ajax({
    url: "http://siteurl/_api/web/lists",
    type: "GET",
    headers: {
        "ACCEPT","application/json;odata=verbose",
        "Authorization", "Bearer " + accessToken
    },
    success: function(data) {
        var listTitle = data.title; // just an example; not sure if this property exists in your data
        $("$myDiv").append('<p>' + listTitle + '</p>');
    }
});

See jQuery official documentation:

http://api.jquery.com/jQuery.ajax/

There are a lot of examples.

EDIT

If your call return one serializable object you can do something like this:

$.ajax({
   url: http:// site url/_api/web/lists,
   type: "GET",
   headers: {
      "ACCEPT","application/json;odata=verbose",
      "Authorization", "Bearer " + accessToken
   },
   success: function(data) {
    $.each(data, function(index, elem){
        //... do some work where ...
        alert(elem);
    });
  }
});

Need Your Help

Calling instance methods from Class methods in ruby

ruby-on-rails ruby function-calls instance-methods class-method

Is this the right way of calling an Instance method from a class method? Here the instance_var is passed with the Name object. I want to invoke func1 from the instance_var object passed to the class

Search for files except in a given directory

linux shell find

I have a directory ./src with files. I would like to extract all .c files in it, except those .c files that are in ./src/test. I have tried variants of