Now that I get a response, I want to deserialize it


#1

Thanks to everyone who helped me to successfully issue requests to the API! I will continue working on making my code more secure using OAuth. In the meantime, I want to start working with the data I get back. Are there predefined objects in a library somewhere that I can deserialize to? I have looked but have found nothing but it must be I am not searching well, as I would think everyone does this.

For example, if my response json looks like this:
{
“data”: [
{
“text”: “added to Things To Buy”,
“created_at”: “2011-12-21T23:23:01.259Z”,
“type”: “system”,
“id”: 2001,
“created_by”: {
“id”: 5678,
“name”: “Greg Sanchez”
}
},
{
“text”: “Again? Wow, we really go through this stuff fast.”,
“created_at”: “2012-01-02T21:32:40.112Z”,
“type”: “comment”,
“id”: 2002,
“created_by”: {
“id”: 1234,
“name”: “Tim Bizarro”
}
}
]
}

I want to serialize it like this:
Story story = JsonConvert.DeserializeObject(json);
And then access the individual members of the story object.

Specifically, my goal is to present in a memoedit control in my application all the Notes that have been entered into asana.

Thanks for any help/doc/samples, etc.


#2

I’ve deserialized it. It was more trivial than I thought:

public class MyClassX
{
    public List<RootObjectX> data { get; set; }
}
public class RootObjectX
{
    public string id { get; set; }
    public string created_at { get; set; }
    public CreatedBy created_by { get; set; }
    public string text { get; set; }
    public string type { get; set; }
}
public class CreatedBy
{
    public string id { get; set; }
    public string name { get; set; }
}

My question now is…I am looping through my response like so:

        var myClass = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<MyClassX>(response);
        foreach (var item in myClass.data)
        {
            Console.WriteLine(string.Format("{0}", item.text));
        }

And I see all the text. I only want the text that is actually a note. For example, I don’t want: “added mmock as a follower”. I do want “Called Bob and left a message, looking to schedule electrical work.” Is there someway to differentiate between the “notes” that get generated as a byproduct of assigning a task to a person, etc and “notes” that are the user typing in the “write a comment” field?


#3

I see now these are type comment vs system. Thanks.


#4

Hey you can keep only stories with type: comment

You can find more at https://asana.com/developers/api-reference/stories