Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // For each result in the data.
- foreach (var result in results["data"])
- {
- // ID for each Asana task in the data.
- string id = (string)result["id"];
- // Deserialize the JSON data so we can use it with an object and its properties.
- deserialize.SetJsonData(requestAsana.getSingleAsanaTask(id));
- // Add data to the list.
- asanaDataList.Add(deserialize.Data);
- }
- private AsanaRootData root = new AsanaRootData();
- public string jsonData;
- public string SetJsonData(string json)
- {
- this.jsonData = json;
- root = JsonConvert.DeserializeObject<AsanaRootData>(jsonData);
- return json;
- }
- public string getSingleAsanaTask(string taskID)
- {
- try
- {
- // Make a request variable with URL and ID.
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(taskURL + taskID);
- // Speed up requests.
- request.Proxy = null;
- // Encode authentication value.
- String encoded = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(auth));
- // Add authentication to header.
- request.Headers.Add("Authorization", "Basic " + encoded);
- // Response variable.
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- // Get the stream associated with the response.
- Stream receiveStream = response.GetResponseStream();
- // Pipes the stream to a higher level stream reader with the required encoding format.
- StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
- return readStream.ReadToEnd();
- }
- catch (WebException e)
- {
- Debug.WriteLine("nInvalid Asana task IDn");
- }
- return "";
- }
Add Comment
Please, Sign In to add comment