0

Normally I would use jQuery to get data from listdata.svc like this:

$.getJSON(listUrl,
            function (data) {
                $.each(data.d.results,
                function (i, result) {

A little clarification. This is my data source:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xml:base="http://contoso/_vti_bin/listdata.svc/">
  <title type="text">UnitsUnit</title>
  <id>http://contoso/_vti_bin/listdata.svc/UnitsUnit</id>
  <entry m:etag="W/&quot;5&quot;">
    <id>http://contoso/_vti_bin/listdata.svc/UnitsUnit(1)</id>
    <title type="text">This is the normal title ...</title>
    <link rel="..." title="..." href="..." />
    <link rel="..." title="..." href="..." />
      <m:inline>
        <feed>
          <title type="text">Subunits</title>
          <id>http://contoso/_vti_bin/listdata.svc/UnitsUnit(1)/Subunits</id>
          <updated>2013-12-04T08:37:07Z</updated>
          <link rel="self" title="Subunits" href="UnitsUnit(1)/Subunits" />
          <entry m:etag="W/&quot;5&quot;">
            <id>http://contoso/_vti_bin/listdata.svc/Units(15)</id>
            <title type="text">**I NEED THIS TITLE**</title>
            <link rel="..." title="..." href="..." />
            <link rel="..." title="..." href="..." />
            <content type="application/xml">
              <m:properties>
                <d:....>.....</d:....>
                <d:....>.....</d:....>
              </m:properties>
            </content>
          </entry>
          <entry m:etag="W/&quot;9&quot;">
            <id>http://contoso/_vti_bin/listdata.svc/Units(16)</id>
            <title type="text">**AND I NEED THIS TITLE**</title>
            <link rel="..." title="..." href="..." />
            <link rel="..." title="..." href="..." />
            <category term="Microsoft.SharePoint.DataService.UnitsItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
            <content type="application/xml">
              <m:properties>
                <d:....>.....</d:....>
                <d:....>.....</d:....>
              </m:properties>
            </content>
          </entry>
        </feed>
      </m:inline>
    </link>
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/OprettetAf" type="application/atom+xml;type=entry" title="OprettetAf" href="UnitsUnit(1)/OprettetAf" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ÆndretAf" type="application/atom+xml;type=entry" title="ÆndretAf" href="UnitsUnit(1)/ÆndretAf" />
    <content type="application/xml">
      <m:properties>
        <d:Title>I don't need this one ...</d:Title>
        <d:UnitId m:type="Edm.Int32">8</d:EnhedId>
      </m:properties>
    </content>
  </entry>
</feed>

I need the titles from the m:inline > feed > entry > title ...

Update: Using console.log(JSON.stringify(data.d.results)) yields this object:

LOG: [{
"__metadata":{...},
"ContentTypeId":"0x0100A9CFFA37DE22C641B71785403A8E5571",
"Title":"This title is what i get with data.d.results[i].Title",
"Unit":{"__deferred":{"uri":"..."}},
"UnitId":8,
"Subunits":{
"results":[{
  "__metadata":{...},
  "ContentTypeId":"0x01009D2BABDBD41F8543A022ECD6225898E4",
  "Title":"This title is what I need",
  "Path":"..."},
  {"__metadata":{...},
  "ContentTypeId":"0x01009D2BABDBD41F8543A022ECD6225898E4",
  "Title":"And this one",
  ...
0

The title should be in result.Title inside your function.

data.d.results[].Title

You can do a console.log(result) in the function in order to print all of the objects out to the console (F12 or Ctrl+Shift+K in Firefox) so you can browse the values.

When working with JS you can do some fiddling around in the console to help expedite the development in this way.

  • Hi Hugh - thx for your answer. I added my data source in the original post. I still can't dig into the nodes I need ... Thanks again :) – user21162 Dec 4 '13 at 11:30
  • in the jquery request do you have the header for Accept:application/json; odata=verbose? If not you might want to use the SP.RequestExecutor instead and JSON.parse the result. – Hugh Wood Dec 4 '13 at 11:42
  • never really used console.log() ... Which is awesome for debugging - thanks. I updated my post with the object that is the result from data.d.results ... Cheers :) – user21162 Dec 4 '13 at 13:01
0

Given your results, and the title you identified, the first title would be:

data.d.results[0].Subunits.results[0].Title

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy