1

I'm working on an implementation of workfront api and my application. This is suppose to be simple. Perhaps my code will explain better.

JToken tasks = client.Search(ObjCode.TASK, new { fields = "ID, extRefID, assignedTo:name" });
taskid = c.Value<string>("ID");
workItem = c.Value<string>("extRefID");
taskAssgTo = c.Value<string>("assignedTo:name");

Now, taskid and workItem return values correctly. I'm having trouble understanding why taskAssgTo will always return null. When debuggin, I can clearly see that assignedTo:name has correct values, but for some reason I will not assign it to taskAssgTo. (taskAssgTo is a string variable).

This is how it looks when retrieving the data using REST:

{
  "ID": "4c78285f00000908ea8cfd66e084939f",
  "extRefId": "4561",
  "assignedTo": {
    "ID": "4c78285f00000908ea8cfd66e084215a",
    "name": "Admin User"
  } 
}

Please I would appreciate an explanation and a possible solution to this. Thanks in advance!

hbulens
  • 1,872
  • 3
  • 24
  • 45
JoseStack
  • 167
  • 2
  • 12
  • @Blast_dan has the correct answer below. What is being returned is basically a complex object and assignedTo has a property "name". To get to the value you would use assignedTo.name. – Stephen Brickner Nov 09 '15 at 17:27

1 Answers1

1

I don't see any documentation that says that you can access child values in the manner you are trying to access them.

I would try using dot notation instead, such as

taskAssgTo = c.Value<string>("assignedTo.name");

or following the link below to see how to navigate a JObject hierarchy

Searching for a specific JToken by name in a JObject hierarchy

Community
  • 1
  • 1
Blast_dan
  • 1,135
  • 9
  • 18
  • Thank you! tasks.SelectToken("data[0].assignedTo.name").ToString(); works better. Thanks for showing me how the toke.path works. I'm really new at working with json and workfront api, and any help is greatly appreciated. – JoseStack Nov 09 '15 at 18:02