C# - Json Deserialize - Cannot deserialize the Json Object - c#

I am new to using the Json format with serializing and deserializing, I am using Json.Net.
As a little activity I decided to use the API from a game that I play to retrieve some simple statistics.
However, I am trying to put this Json into classes (created by json2csharp) but I get the exception.
Additional information: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[TornCityAPI.PlayerStatistics.Stats+RootObject]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
and here is the code.
using Microsoft.Win32;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.NetworkInformation;
using System.Windows.Forms;
namespace TornCityAPI
{
public partial class Form_Main : Form
{
// to hold the users api key
private string apiKey;
public string APIKey
{
get { return apiKey; }
set { apiKey = value; }
}
// location in the registry
private string registryLocation = #"HKEY_CURRENT_USER\TornCityAPI\Watch_App";
public string RegistryLocation
{
get { return registryLocation; }
}
// the url which will be used to retrive information
private string apiUrl = "https://api.torn.com/user/?selections=&key=";
public string ApiUrl
{
get { return apiUrl; }
set { apiUrl = value; }
}
// in case of a network disconnect, we could server the previous results instead.
private string previousTornStats;
public string PreviousTronStats
{
get { return previousTornStats; }
set { previousTornStats = value; }
}
public Form_Main()
{
InitializeComponent();
}
private void Form_Main_Load(object sender, EventArgs e)
{
CheckNetworkConnection();
// if the api key does not exists within the registry
if (Registry.GetValue(registryLocation, "Watch_App", null) == null)
{
// ask the user to insert theirs and open the form to allow that
MessageBox.Show("Please enter your torn API key!");
Form_APIKey apiWindow = new Form_APIKey();
apiWindow.ShowDialog(this);
}
// otherwise
else
{
// connect the url with the api key to get the full, working url to get the information
APIKey = (string)Registry.GetValue(registryLocation, "Watch_App", null);
ApiUrl += APIKey;
MessageBox.Show(apiUrl);
}
}
private void timer_UpdateStats_Tick(object sender, EventArgs e)
{
CheckNetworkConnection();
UpdateTornStats();
}
void UpdateTornStats()
{
using (var webClient = new WebClient())
{
var json = new WebClient().DownloadString(ApiUrl);
var list = JsonConvert.DeserializeObject<List<PlayerStatistics.Stats.RootObject>>(json);
Console.WriteLine(list.Count);
}
}
void CheckNetworkConnection()
{
// if they are not connected to the internet
if (NetworkInterface.GetIsNetworkAvailable() == false)
{
Console.WriteLine("You are not connected to the internet!" + "\n" + "Please connect and restart!");
return;
}
}
}
}
Specifically:
void UpdateTornStats()
{
using (var webClient = new WebClient())
{
var json = new WebClient().DownloadString(ApiUrl);
var list = JsonConvert.DeserializeObject<List<PlayerStatistics.Stats.RootObject>>(json);
Console.WriteLine(list.Count);
}
}
Here is the class I try to put it into.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TornCityAPI.PlayerStatistics
{
class Stats
{
public class Life
{
public int current { get; set; }
public int maximum { get; set; }
public int increment { get; set; }
public int interval { get; set; }
public int ticktime { get; set; }
public int fulltime { get; set; }
}
public class Job
{
public string position { get; set; }
public int company_id { get; set; }
public string company_name { get; set; }
}
public class Faction
{
public string position { get; set; }
public int faction_id { get; set; }
public int days_in_faction { get; set; }
public string faction_name { get; set; }
}
public class Married
{
public int spouse_id { get; set; }
public string spouse_name { get; set; }
public int duration { get; set; }
}
public class Icons
{
public string icon6 { get; set; }
public string icon3 { get; set; }
public string icon8 { get; set; }
public string icon27 { get; set; }
public string icon9 { get; set; }
}
public class RootObject
{
public string rank { get; set; }
public int level { get; set; }
public string gender { get; set; }
public string property { get; set; }
public string signup { get; set; }
public int awards { get; set; }
public int friends { get; set; }
public int enemies { get; set; }
public int forum_posts { get; set; }
public int karma { get; set; }
public int age { get; set; }
public string role { get; set; }
public int donator { get; set; }
public int player_id { get; set; }
public string name { get; set; }
public int property_id { get; set; }
public string last_action { get; set; }
public Life life { get; set; }
public List<string> status { get; set; }
public Job job { get; set; }
public Faction faction { get; set; }
public Married married { get; set; }
public Icons icons { get; set; }
}
}
}
I dont really know how to lay this out or what class should be created from the Json. (However I assume its the root as it has references to the other classes)
Finally, here is the Json which is downloaded to a string:
{
"rank": "Reasonable Punchbag",
"level": 22,
"gender": "Male",
"property": "Ranch",
"signup": "2013-08-01 07:59:43",
"awards": 58,
"friends": 2,
"enemies": 2,
"forum_posts": 25,
"karma": 4,
"age": 1234,
"role": "Civilian",
"donator": 1,
"player_id": 1761543,
"name": "GamingAnonymous",
"property_id": 16693,
"last_action": "18 minutes ago",
"life": {
"current": 429,
"maximum": 1072,
"increment": 53,
"interval": 300,
"ticktime": 258,
"fulltime": 3858
},
"status": [
"In hospital for 3 hrs 4 mins - Hospitalized by someone",
""
],
"job": {
"position": "Employee",
"company_id": 61582,
"company_name": "streamTV - hiring 33k man"
},
"faction": {
"position": "Member",
"faction_id": 17845,
"days_in_faction": 268,
"faction_name": "The Watchers"
},
"married": {
"spouse_id": 2024099,
"spouse_name": "Anonymous_Hugo",
"duration": 62
},
"icons": {
"icon6": "Male",
"icon3": "Donator",
"icon8": "Married - To Anonymous_Hugo",
"icon27": "Company - Employee of streamTV - hiring 33k man (Television Network)",
"icon9": "Faction - Member of The Watchers",
"icon15": "Hospital - Hospitalized by someone - 03:04:17 "
}
}
Any help would be greatly appreciated, thanks.

The error message is pretty straightforward. You're trying to deserialize object to List of RootObject.
Use this snippet:
void UpdateTornStats()
{
using (var webClient = new WebClient())
{
var json = new WebClient().DownloadString(ApiUrl);
var list = JsonConvert.DeserializeObject<PlayerStatistics.Stats.RootObject>(json);
Console.WriteLine(list.Count);
}
}

Related

How do I consume Api for C# project

I am trying to consume an Api for c# project.
I have the request body sample as follows:
{
"tx_ref":"hooli-tx-1920bbtytty",
"amount":"100",
"currency":"NGN",
"redirect_url":"https://webhook.site/9d0b00ba-9a69-44fa-a43d-a82c33c36fdc",
"payment_options":"card",
"meta":{
"consumer_id":23,
"consumer_mac":"92a3-912ba-1192a"
},
"customer":{
"email":"user#gmail.com",
"phonenumber":"080****4528",
"name":"Yemi Desola"
},
"customizations":{
"title":"Pied Piper Payments",
"description":"Middleout isn't free. Pay the price",
"logo":"https://assets.piedpiper.com/logo.png"
}
}
I want to convert the code to C#, I did it as below, but the "meta", "customer", "customizations" are nested in the request, when I tried to reproduce the nested part of the code to c# I get an error.
Please how do I place my C# code to reflect the body with the nested part of the code?
var keyValues = new Dictionary<string, string>
{
{ "tx_ref", "N-872653uy09-9"},
{ "amount", "500"},
{ "currency","NGN"},
{ "redirect_url","mysite.com/ConcludeFunding.aspx"},
{ "payment_options","card"},
{ "meta"," "},
{ "customer"("email",EmailV) },
{ "customizations","mysite.com/Assets/Logo.jpg"},
};
//serialization using Newtonsoft JSON
string JsonBody = JsonConvert.SerializeObject(keyValues);
For this type of situation, I would create a root class. Then I would assign value to the class object and finally I would serialize the object using Newtonsoft JSON.
Code:
using Newtonsoft.Json;
using System;
namespace Solve
{
internal class Program
{
public class Meta
{
public int consumer_id { get; set; }
public string consumer_mac { get; set; }
}
public class Customer
{
public string email { get; set; }
public string phonenumber { get; set; }
public string name { get; set; }
}
public class Customizations
{
public string title { get; set; }
public string description { get; set; }
public string logo { get; set; }
}
public class Root
{
public string tx_ref { get; set; }
public string amount { get; set; }
public string currency { get; set; }
public string redirect_url { get; set; }
public string payment_options { get; set; }
public Meta meta { get; set; }
public Customer customer { get; set; }
public Customizations customizations { get; set; }
}
static void Main(string[] args)
{
var rootObj = new Root()
{
tx_ref = "N-872653uy09-9",
amount = "500",
currency = "NGN",
redirect_url = "mysite.com/ConcludeFunding.aspx",
payment_options = "card",
meta = new Meta()
{
consumer_id = 23,
consumer_mac = "92a3-912ba-1192a"
},
customizations = new Customizations()
{
title = "Pied Piper Payments",
description = "Middleout isn't free. Pay the price",
logo = "https://assets.piedpiper.com/logo.png"
},
customer = new Customer()
{
email = "user#gmail.com",
phonenumber = "080****4528",
name = "Yemi Desola"
}
};
string json = JsonConvert.SerializeObject(rootObj);
Console.WriteLine(json);
}
}
}

C# - Store JSON array string into SQL table

I am new to C#
Following is the JSON string I am getting from the web API.
I am trying to store the JSON string into a class and then store the JSON string into an SQL table.
But the C# code is failing to deserialize JSON into class. And the message box returns the null exception error.
JSON
{
"Count":3,
"data":[
{
"Cost1":{
"amount":111,
"currencyCode":"ABC"
},
"Cost2":{
"amount":22.2,
"currencyCode":"XYZ"
},
"Id":"007"
},
{
"Cost1":{
"amount":555,
"currencyCode":"ABC"
},
"Cost2":{
"amount":444,
"currencyCode":"XYZ"
},
"Id":"008"
},
{
"Cost1":{
"amount":666,
"currencyCode":"ABC"
},
"Cost2":{
"amount":8882,
"currencyCode":"XYZ"
},
"Id":"009"
}
],
"pending":[
],
"#up":"Test Data"
}
C# Code
public class ParceJSN {
public int Count {
get;
set;
}
public string data {
get;
set;
}
public string pending {
get;
set;
}
public string up {
get;
set;
}
}
public void Main() {
Task < string > task = MakeRequest(db_token); //Returns the JSON string
var fr = task.Result;
ParceJSN rst = JsonConvert.DeserializeObject < ParceJSN > (fr.ToString());
MessageBox.Show(rst.TotalCount.ToString());
Dts.TaskResult = (int) ScriptResults.Success;
}
Your C# model is incorrect. Here's a really handy tool that I use when I need to generate C# classes based on some JSON - json2csharp.com
The correct class is:
public class Cost1 {
public int amount { get; set; }
public string currencyCode { get; set; }
}
public class Cost2 {
public double amount { get; set; }
public string currencyCode { get; set; }
}
public class Datum {
public Cost1 Cost1 { get; set; }
public Cost2 Cost2 { get; set; }
public string Id { get; set; }
}
public class Root {
public int Count { get; set; }
public List<Datum> data { get; set; }
public List<object> pending { get; set; }
[JsonProperty("#up")]
public string Up { get; set; }
}
Now that you have the correct model, you can now do the following to deserialize your JSON string into a Root object which is defined above:
Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(YOUR_JSON_STRING);

C# Deserialize Facebook JSON starting with random key

Hello still a newb (student) to C#, I was wondering how to deserialize this kind of JSON data (with JsonConvert and a model class)
JSON example:
{
"435321729828514": {
"id": "435321729828514",
"name": "Kursaal Oostende"
},
"56302776046": {
"id": "56302776046",
"name": "Caf\u00e9 Charlatan"
}
}
Repository class:
public class FB
{
public async static Task<FBModel> Entries(string ids)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(#"https://graph.facebook.com/v2.8/");
HttpResponseMessage response = await client.GetAsync("?ids="+ ids +"&fields=id,name&access_token=secret_token");
if (response.IsSuccessStatusCode)
{
string s = await response.Content.ReadAsStringAsync();
FBModel entries = JsonConvert.DeserializeObject<FBModel>(s);
return entries;
}
else
return null;
}
}
}
Model:
public class FBModel
{
public string ID { get; set; }
public string Name { get; set; }
public override string ToString()
{
return ID + ": " + Name;
}
}
MainPage.xaml (call):
private static FBModel _entries; // global variable
// ...
_entries = await FB.Entries(ids_to_pass);
--------- Solved (model) ----------
public class FBModel
{
#region properties
public string Id { get; set; }
public string Name { get; set; }
public Events Events { get; set; }
#endregion
}
public class Events
{
#region props
public List<Datum> Data { get; set; }
public Paging Paging { get; set; }
#endregion
}
public class Datum
{
#region props
public string Description { get; set; }
public string End_time { get; set; }
public string Name { get; set; }
public Place Place { get; set; }
public string Start_time { get; set; }
public string Id { get; set; }
#endregion
}
public class Place
{
#region props
public string Id { get; set; }
public string Name { get; set; }
public Location Location { get; set; }
#endregion
}
public class Location
{
#region props
public string City { get; set; }
public string Country { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
public string Street { get; set; }
public string Zip { get; set; }
#endregion
}
#region not important
public class Paging
{
#region props
public Cursors Cursors { get; set; }
public string Next { get; set; }
#endregion
}
public class Cursors
{
#region props
public string Before { get; set; }
public string After { get; set; }
#endregion
}
-------- Solved (complete JSON) ----------
{
"435321729828514": {
"id": "435321729828514",
"name": "Kursaal Oostende",
"events": {
"data": [
{
"description": "CHRISTOFF, ...",
"end_time": "2017-11-25T23:00:00+0100",
"name": "Vrienden Voor Het Leven",
"place": {
"name": "Kursaal Oostende",
"location": {
"city": "Oostende",
"country": "Belgium",
"latitude": 51.2312299,
"longitude": 2.9126599,
"street": "Westhelling 12",
"zip": "8400"
},
"id": "435321729828514"
},
"start_time": "2017-11-25T20:00:00+0100",
"id": "161310354323914"
}
],
"paging": {
"cursors": {
"before": "MTYxMzEwMzU0MzIzOTE0",
"after": "MTYxMzEwMzU0MzIzOTE0"
},
"next": "https://graph.facebook.com/v2.8/435321729828514/events?access_token=EAAH2ZAZAq846IBAM9ZAX0LWpDxlzFaPr8jNOxDct2tZBw7YJAtnYxIlVud67hiXI51ybmhLcz4AhMtiVxZBBcPixx9wB9ntF1ZBRhSIuSxeUu83mg6tZBc0BseLpdmkWuu7bohQxXvvLUe67pjETnqDOj8PzFZAXHHAyqEqYrWOXvAZDZD\u002522&pretty=1&limit=1&after=MTYxMzEwMzU0MzIzOTE0"
}
}
}
}
-------- Solved (Repository) ---------
public async static Task<List<FBModel>> Entries(string ids)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(#"https://graph.facebook.com/v2.8/");
HttpResponseMessage response = await client.GetAsync("?ids="+ ids +"&fields=id,name,events.limit(60)&access_token=secret_token");
if (response.IsSuccessStatusCode)
{
string s = await response.Content.ReadAsStringAsync();
var entries = JsonConvert.DeserializeObject<Dictionary<string, FBModel>>(s);
List<FBModel> data = entries.Select(item => item.Value).ToList();
return data;
}
else
return null;
}
}
This is what you have to do.
Step 1: Convert your json to Dictionary.
var dataDictionary = JsonConvert.DeserializeObject<Dictionary<string, FBModel>>(yourJsonstring);
Step 2: Then get list of object
List<FBModel> data=new List<FBModel>();
foreach (var item in dataDictionary)
{
data.Add(item.Value);
}
Step 2 can be done as a linq query
List<FBModel> data= dataDictionary.Select(item => item.Value).ToList();
Update
your class structure should be like below to access the event data.
public class FBModel
{
public string ID { get; set; }
public string Name { get; set; }
public Events Events { get; set; }
public override string ToString()
{
return ID + ": " + Name;
}
}
public class Events
{
public List<Data> Data { get; set; }
}
public class Data
{
public string Description { get; set; }
public string End_Time { get; set; }
public string Name { get; set; }
public Place Place { get; set; }
public string Start_Time { get; set; }
public string Id { get; set; }
}
public class Place
{
public string Name { get; set; }
public Location Location { get; set; }
}
public class Location
{
public string City { get; set; }
public string Country { get; set; }
public string Latitude { get; set; }
public string Longitude { get; set; }
public string Street { get; set; }
public string Zip { get; set; }
}

Json.Net serialise collection into named attributes

I am creating a Xamarin app with API calls managed by Refit and other Paul Betts libraries and was looking at serialising a collection of objects into a Json attributed array.
The question I have is how do I serialise the collection of MemberSlot objects in the MemberBooking type, using Json.Net, into the desired Json?
The names of the objects will always be numbers 1 -> 4 but some or all may not be present.
Question
Could I just change the List property in the MemberBooking object to a Dictionary and populate the string key appropriately?
Object heirarchy
public class MemberBookingRequest
{
[JsonProperty("member_booking_request")]
public MemberBooking Booking { get; set; }
}
public class MemberBooking
{
[JsonProperty("course_id")]
public int CourseId { get; set; }
[JsonProperty("date")]
public string TeeDate { get; set; }
[JsonProperty("time")]
public string TeeTime { get; set; }
[JsonProperty("slots")]
public List<MemberSlot> Slots { get; set; }
}
public class MemberSlot
{
[JsonIgnore]
public int Id { get; set; }
[JsonProperty("type")]
public BookingType Type { get; set; }
[JsonProperty("holes")]
public int Holes { get; set; }
[JsonProperty("user_id")]
public int MemberId { get; set; }
}
Current Json
{
"member_booking_request":{
"course_id":1,
"date":"2016-09-29",
"time":"09:00",
"slots":[
{
"type":"Member",
"holes":18,
"user_id":110
},
{
"type":"Member",
"holes":18,
"user_id":111
},
{
"type":"Member",
"holes":18,
"user_id":112
},
{
"type":"Member",
"holes":18,
"user_id":117
]
}
}
}
Desired Json
{
"member_booking_request":{
"course_id":1,
"date":"2016-09-29",
"time":"09:00",
"slots":{
"1":{
"type":"Member",
"holes":18,
"user_id":110
},
"2":{
"type":"Member",
"holes":18,
"user_id":111
},
"3":{
"type":"Member",
"holes":18,
"user_id":112
},
"4":{
"type":"Member",
"holes":18,
"user_id":117
}
}
}
}
You'll have to change the way you create Slots property. Assign MemberSlot.Id as key, MemberSlot itself as value when filling Slots dictionary.
public class MemberBooking
{
[JsonProperty("course_id")]
public int CourseId { get; set; }
[JsonProperty("date")]
public string TeeDate { get; set; }
[JsonProperty("time")]
public string TeeTime { get; set; }
[JsonProperty("slots")]
public Dictionary<int,MemberSlot> Slots { get; set; }
}
This sample will give the your desired json output,using a dictionary
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace jsonconversion
{
public class Program
{
public static void Main(string[] args)
{
Dictionary<int,MemberSlot> slots=new Dictionary<int, MemberSlot>();
MemberSlot slot1 = new MemberSlot() {Id = 1, Holes =2, MemberId = 1};
slots.Add(1,slot1);
MemberBookingRequest mbr = new MemberBookingRequest
{
Booking = new MemberBooking()
{CourseId = 1, TeeDate ="",TeeTime = "",Slots = slots}
};
string jd = JsonConvert.SerializeObject(mbr);
Console.WriteLine(jd);
}
}
public class MemberBookingRequest
{
[JsonProperty("member_booking_request")]
public MemberBooking Booking { get; set; }
}
public class MemberBooking
{
[JsonProperty("course_id")]
public int CourseId { get; set; }
[JsonProperty("date")]
public string TeeDate { get; set; }
[JsonProperty("time")]
public string TeeTime { get; set; }
[JsonProperty("slots")]
public Dictionary<int, MemberSlot> Slots { get; set; }
}
public class MemberSlot
{
[JsonIgnore]
public int Id { get; set; }
[JsonProperty("holes")]
public int Holes { get; set; }
[JsonProperty("user_id")]
public int MemberId { get; set; }
}
}

extract data from json in asp.net c#

I'm trying to extract some data from json. I've been looking for a solution either in JSS or Json.net but haven't been able to figure this problem out. this is how my Json looks like:
Note: i Have tested and the mapping and decentralization works! I'm looking for a way to extract specifc data from the json!
Thanks in Advance!
{
"tasks":[
{
"id":"tmp_fk1345624806538",
"name":"Gantt editor ",
"code":"",
"level":0,
"status":"STATUS_ACTIVE",
"start":1346623200000,
"duration":5,
"end":1347055199999,
"startIsMilestone":false,
"endIsMilestone":false,
"assigs":[
{
"resourceId":"tmp_3",
"id":"tmp_1345625008213",
"roleId":"tmp_1",
"effort":7200000
}
],
"depends":"",
"description":"",
"progress":0
},
{
"id":"tmp_fk1345624806539",
"name":"phase 1",
"code":"",
"level":1,
"status":"STATUS_ACTIVE",
"start":1346623200000,
"duration":2,
"end":1346795999999,
"startIsMilestone":false,
"endIsMilestone":false,
"assigs":[
{
"resourceId":"tmp_1",
"id":"tmp_1345624980735",
"roleId":"tmp_1",
"effort":36000000
}
],
"depends":"",
"description":"",
"progress":0
},
{
"id":"tmp_fk1345624789530",
"name":"phase 2",
"code":"",
"level":1,
"status":"STATUS_SUSPENDED",
"start":1346796000000,
"duration":3,
"end":1347055199999,
"startIsMilestone":false,
"endIsMilestone":false,
"assigs":[
{
"resourceId":"tmp_2",
"id":"tmp_1345624993405",
"roleId":"tmp_2",
"effort":36000000
}
],
"depends":"2",
"description":"",
"progress":0
}
],
"resources":[
{
"id":"tmp_1",
"name":"Resource 1"
},
{
"id":"tmp_2",
"name":"Resource 2"
},
{
"id":"tmp_3",
"name":"Resource 3"
}
],"roles":[
{
"id":"tmp_1",
"name":"Project Manager"
},
{
"id":"tmp_2",
"name":"Worker"
}
],
"canWrite":true,
"canWriteOnParent":true,
"selectedRow":0,
"deletedTaskIds":[],
}
i've already mapped as follow
public class Rootobject
{
public Task[] tasks { get; set; }
public Resource[] resources { get; set; }
public Role[] roles { get; set; }
public bool canWrite { get; set; }
public bool canWriteOnParent { get; set; }
public int selectedRow { get; set; }
public object[] deletedTaskIds { get; set; }
}
public class Task
{
public string id { get; set; }
public string name { get; set; }
public string code { get; set; }
public int level { get; set; }
public string status { get; set; }
public long start { get; set; }
public int duration { get; set; }
public long end { get; set; }
public bool startIsMilestone { get; set; }
public bool endIsMilestone { get; set; }
public Assig[] assigs { get; set; }
public string depends { get; set; }
public string description { get; set; }
public int progress { get; set; }
}
public class Assig
{
public string resourceId { get; set; }
public string id { get; set; }
public string roleId { get; set; }
public int effort { get; set; }
}
public class Resource
{
public string id { get; set; }
public string name { get; set; }
}
public class Role
{
public string id { get; set; }
public string name { get; set; }
}
and I need to extract following information from my json.(from specific Task in may json! for example the first one with id : tmp_fk1345624806538 ).
Note: i'm getting my json from a json file as follow:
string startDate; // this is what i need to extract
string endDate; // this is what i need to extract
string Progress; // this is what i need to extract
public void load()
{
GC.GClass l = new GC.GClass();
string jsonString = l.load(); // i get my json from a json file
Rootobject project = JsonConvert.DeserializeObject<Rootobject>(jsonString);
}
You can use LINQ to query the object quickly.
Task task = project.tasks.FirstOrDefault(t=> t.id == "tmp_fk1345624806538");
Test task, and if null then there was not task with matching id. If you are sure that there will be a matching task your can just use .First(), but it will throw an exception if there is no match in the list
You'll need to add a using System.Linq; if you don't have that already.

Categories