Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

JSON question

i,

If my returned JSON is of the format as mentioned below, how do i get the Value "Project.Description"? using JQuery?

                                               
REST Request

function getitems() {
    var url = "http://sc-spstd-dev.mysite.com/it/PM/_api/web/lists/getbytitle('IT Dashboard Project')/items?$filter=Id eq 39";
    $.ajax({
        url: url,
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            if (data.d.results.length == 1) {
                alert("success: " + data.d.results.Project.Description);

                $("#dataholder").html(JSON.stringify(data));
                //success(data.d.results[0]);
            }
            else {

                alert("failure: " + JSON.stringify(data));

                //failure("Multiple results obtained for the specified Id value");
            }
        },
        error: function (data) {
            //failure(data);
        }
    });
}
Returned JSON

{"d":{"results":[{"__metadata":{"id":"6455ed93-382f-404f-a5ee-8247306f4786","uri":"http://sc-spstd-dev.mySite.com/it/pm/_api/Web/Lists(guid'7bd231eb-d4ac-435e-bf4d-faea7386ff2d')/Items(39)","etag":"\"23\"","type":"SP.Data.IT_x0020_Dashboard_x0020_ProjectListItem"},"FirstUniqueAncestorSecurableObject":{"__deferred":{"uri":"http://sc-spstd-dev.mySite.com/it/pm/_api/Web/Lists(guid'7bd231eb-d4ac-435e-bf4d-faea7386ff2d')/Items(39)/FirstUniqueAncestorSecurableObject"}},"RoleAssignments":{"__deferred":{"uri":"http://sc-spstd-dev.mySite.com/it/pm/_api/Web/Lists(guid'7bd231eb-d4ac-435e-bf4d-faea7386ff2d')/Items(39)/RoleAssignments"}},"AttachmentFiles":{"__deferred":{"uri":"http://sc-spstd-dev.mySite.com/it/pm/_api/Web/Lists(guid'7bd231eb-d4ac-435e-bf4d-faea7386ff2d')/Items(39)/AttachmentFiles"}},"ContentType":{"__deferred":{"uri":"http://sc-spstd-dev.mySite.com/it/pm/_api/Web/Lists(guid'7bd231eb-d4ac-435e-bf4d-faea7386ff2d')/Items(39)/ContentType"}},"FieldValuesAsHtml":{"__deferred":{"uri":"http://sc-spstd-dev.mySite.com/it/pm/_api/Web/Lists(guid'7bd231eb-d4ac-435e-bf4d-faea7386ff2d')/Items(39)/FieldValuesAsHtml"}},"FieldValuesAsText":{"__deferred":{"uri":"http://sc-spstd-dev.mySite.com/it/pm/_api/Web/Lists(guid'7bd231eb-d4ac-435e-bf4d-faea7386ff2d')/Items(39)/FieldValuesAsText"}},"FieldValuesForEdit":{"__deferred":{"uri":"http://sc-spstd-dev.mySite.com/it/pm/_api/Web/Lists(guid'7bd231eb-d4ac-435e-bf4d-faea7386ff2d')/Items(39)/FieldValuesForEdit"}},"File":{"__deferred":{"uri":"http://sc-spstd-dev.mySite.com/it/pm/_api/Web/Lists(guid'7bd231eb-d4ac-435e-bf4d-faea7386ff2d')/Items(39)/File"}},"Folder":{"__deferred":{"uri":"http://sc-spstd-dev.mySite.com/it/pm/_api/Web/Lists(guid'7bd231eb-d4ac-435e-bf4d-faea7386ff2d')/Items(39)/Folder"}},"ParentList":{"__deferred":{"uri":"http://sc-spstd-dev.mySite.com/it/pm/_api/Web/Lists(guid'7bd231eb-d4ac-435e-bf4d-faea7386ff2d')/Items(39)/ParentList"}},"FileSystemObjectType":0,"Id":39,"ContentTypeId":"0x0100C744EEAFCDCE644291DDD76900E3142D040100FE7A91994E36DE429609362ECC5ED4D2","Title":null,"Project_x0020_Name":"Silver Bullet","Objective":null,"Dept":{"__metadata":{"type":"SP.Taxonomy.TaxonomyFieldValue"},"Label":"45","TermGuid":"7551f9e3-5f42-4a40-86b9-9d5232238c44","WssId":45},"Team":{"__metadata":{"type":"SP.Taxonomy.TaxonomyFieldValue"},"Label":"46","TermGuid":"79659ae1-3b19-4104-b58b-8dc14833b88f","WssId":46},"PMId":40,"Tier":{"__metadata":{"type":"SP.Taxonomy.TaxonomyFieldValue"},"Label":"61","TermGuid":"0c76ec04-5136-460f-95b5-c82c0be5d7cf","WssId":61},"Global":true,"RGS":{"results":[{"__metadata":{"type":"SP.Taxonomy.TaxonomyFieldValue"},"Label":"R","TermGuid":"172aacb6-0452-40d7-abdb-e2cf6714bf28","WssId":59},{"__metadata":{"type":"SP.Taxonomy.TaxonomyFieldValue"},"Label":"S","TermGuid":"8655e913-def6-4219-90e4-19f60d99cca9","WssId":65}]},"Project_x0020_Status":{"__metadata":{"type":"SP.Taxonomy.TaxonomyFieldValue"},"Label":"60","TermGuid":"7b3bebae-b863-4a9c-aad2-660def87fc20","WssId":60},"Show_x0020_in_x0020_dashboard":true,"StartDate":"2013-01-01T08:00:00Z","Original_x0020_Go_x002d_Live_x00":"2014-02-04T08:00:00Z","Current_x0020_Go_x002d_Live_x002":"2014-04-04T07:00:00Z","Next_x0020_Gate":"2013-06-06T07:00:00Z","Issue":"
1
","Status_x0020_Overview":"Project used for PM training","Project":{"__metadata":{"type":"SP.FieldUrlValue"},"Description":"Silver Bullet","Url":"http://sc-spstd-dev.mySite.com/it/pm/SilverBullet"},"Current_x0020_Phase":{"__metadata":{"type":"SP.Taxonomy.TaxonomyFieldValue"},"Label":"51","TermGuid":"e251dc81-2329-4110-9611-095cf169dca2","WssId":51},"Prev_x0020_Status":{"__metadata":{"type":"SP.Taxonomy.TaxonomyFieldValue"},"Label":"57","TermGuid":"f65a7b18-9c71-4547-baba-1bf369abcb59","WssId":57},"ID":39,"Modified":"2013-12-11T19:12:20Z","Created":"2013-12-11T19:12:20Z","AuthorId":40,"EditorId":40,"OData__UIVersionString":"1.0","Attachments":false,"GUID":"b2e9a9ad-8c42-46a2-aad0-7001177692b5"}]}}
0
Techsavy
Asked:
Techsavy
1 Solution
 
leakim971PluritechnicianCommented:
replace :
 alert("success: " + data.d.results.Project.Description);
by :
 alert("success: " + data.d.results[0].Project.Description);

test page : http://jsfiddle.net/sse0ujnc/
0
 
TechsavyAuthor Commented:
thank you worked!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now