I'm trying to Deserialize some json using JsonConver.DeserializeObject. however it's not working on some json from the api I'm using. here is a link that does not work: https://api.pokemontcg.io/v1/cards?setCode=smp
and here is a link that does work. https://api.pokemontcg.io/v1/cards?setCode=sm2
I'm not sure why it sometimes works and sometimes not. The data that comes out of it is very similar to each other, just different cards.
Here is the code:
public static async Task<T> GetDataAsync<T>(this HttpClient client, string address, string querystring)
where T : class
{
var uri = address;
if (!string.IsNullOrEmpty(querystring))
{
uri += querystring;
}
var httpMessage = await client.GetStringAsync(uri);
var jsonObject = JsonConvert.DeserializeObject<T>(httpMessage);
return jsonObject;
}
Now my card class
namespace CardAppReal.Lib.Models
{
public class Card
{
public string id { get; set; }
public string name { get; set; }
public string imageUrl { get; set; }
public string imageUrlHiRes { get; set; }
public string supertype { get; set; } // if pokemon, trainer or energy
public string setcode { get; set; }
public int number { get; set; }
public string set { get; set; }
}
}
With a root
using System.Collections.Generic;
using CardAppReal.Lib.Models;
namespace CardAppReal.Lib.Entities
{
public class RootCard
{
public List<Card> cards { get; set; }
}
}
If u could help me out I would find it amazing.
I have tested your json.
this is the Model
namespace Test
{
public class Attack
{
public List<string> cost { get; set; }
public string name { get; set; }
public string text { get; set; }
public string damage { get; set; }
public int convertedEnergyCost { get; set; }
}
public class Weakness
{
public string type { get; set; }
public string value { get; set; }
}
public class Resistance
{
public string type { get; set; }
public string value { get; set; }
}
public class Ability
{
public string name { get; set; }
public string text { get; set; }
public string type { get; set; }
}
public class Card
{
public string id { get; set; }
public string name { get; set; }
public int nationalPokedexNumber { get; set; }
public string imageUrl { get; set; }
public string imageUrlHiRes { get; set; }
public string subtype { get; set; }
public string supertype { get; set; }
public string hp { get; set; }
public List<string> retreatCost { get; set; }
public string number { get; set; }
public string artist { get; set; }
public string rarity { get; set; }
public string series { get; set; }
public string set { get; set; }
public string setCode { get; set; }
public List<string> types { get; set; }
public List<Attack> attacks { get; set; }
public List<Weakness> weaknesses { get; set; }
public List<Resistance> resistances { get; set; }
public string evolvesFrom { get; set; }
public Ability ability { get; set; }
public List<string> text { get; set; }
}
public class RootObject
{
public List<Card> cards { get; set; }
}
}
And this is how I call the Deserialize
RootObject root = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(RootObject.WRONG_JSON);
(NB WRONG_JSON is your json string...)
Related
Trying best how to take the following classes and deserialize a Json file to return each class values back to Simpl+. I am able to receive the Total value but anything in a list I am at a lost.
public class Client
{
public string clientId { get; set; }
public string locale { get; set; }
public string location { get; set; }
public string auxiliaryId { get; set; }
public string description { get; set; }
public string type { get; set; }
public string typeDescription { get; set; }
public Hardware hardware { get; set; }
public Network network { get; set; }
}
public class Hardware
{
public string type { get; set; }
public string softwareVersion { get; set; }
public string serialNumber { get; set; }
public string hardwareVersion { get; set; }
public string model { get; set; }
}
public class Network
{
public string ip { get; set; }
public string mac { get; set; }
public object homepage { get; set; }
public string dhcpSubnet { get; set; }
}
public class Result
{
public List<Client> clients { get; set; }
public string total { get; set; }
public int limit { get; set; }
public int page { get; set; }
}
public class Root
{
public string jsonrpc { get; set; }
public object id { get; set; }
public Result result { get; set; }
}
I was able to resolve this by adding the following to the foreach statement:
args.MyIndex = (ushort)(rootObject.TriplePlayResult.clients.IndexOf(item) + 1);
I have some problems deserializing the following JSON string. On all of my other responses it works really good but not for this one. I tried so many different things and I checked the Stream class about 100 times. I also have used a generated class from json2csharp but all my deserialized Data is NULL.
My code to get the response:
public Stream getStream(string userID)
{
var request = GetRequest("streams/{channelID}", Method.GET);
request.AddUrlSegment("channelID", userID);
var response = restClient.Execute<Stream>(request);
return response.Data;
}
response.Content shows me as example something like that:
{
"stream":
{
"_id":25649270464,
"game":"test",
"broadcast_platform":"other",
"community_id":"xxxxxxxxx",
"community_ids":["xxxxxx"],
"viewers":2421,
"video_height":1080,
"average_fps":61.7876424715,
"delay":0,
"created_at":"2017-07-02T10:01:28Z",
"is_playlist":false,
"stream_type":"live",
"preview":
{
"small":"https://static-cdn.jtvnw.net/previews-ttv/live_user_lostaiming-80x45.jpg",
"medium":"https://static-cdn.jtvnw.net/previews-ttv/live_user_lostaiming-320x180.jpg",
"large":"https://static-cdn.jtvnw.net/previews-ttv/live_user_lostaiming-640x360.jpg",
"template":"https://static-cdn.jtvnw.net/previews-ttv/live_user_lostaiming-{width}x{height}.jpg"
},
"channel":
{
"mature":false,
"status":"Test"
,"broadcaster_language":"de",
"display_name":"LOSTAIMING",
"game":"test",
"language":"en",
"_id":44281267,
"name":"lostaiming",
"created_at":"2013-06-02T16:42:19.329009Z",
"updated_at":"2017-07-02T13:05:11.555285Z",
"partner":true,
"logo":"https://static-cdn.jtvnw.net/jtv_user_pictures/lostaiming-profile_image-e9d7ea0893748d6a-300x300.png",
"video_banner":"https://static-cdn.jtvnw.net/jtv_user_pictures/cc34c6b909a435ae-channel_offline_image-1920x1080.png",
"profile_banner":"https://static-cdn.jtvnw.net/jtv_user_pictures/c187e8871c0f6a2b-profile_banner-480.png",
"profile_banner_background_color":"",
"url":"https://www.twitch.tv/lostaiming",
"views":2292173,
"followers":55672,
"broadcaster_type":"",
"description":"Blubb"
}
}
}
And my Stream class looks like this:
class Stream
{
[JsonProperty("stream")]
public SubStream stream { get; set; }
}
class SubStream
{
[JsonProperty("_id")]
public string ID { get; set; }
[JsonProperty("game")]
public string Game { get; set; }
[JsonProperty("broadcast_platform")]
public string BroadcastPlatform { get; set; }
[JsonProperty("community_id")]
public string CommunityID { get; set; }
[JsonProperty("community_ids")]
public List<object> CommunityIDS { get; set; }
[JsonProperty("viewers")]
public long Viewers { get; set; }
[JsonProperty("video_height")]
public long VideoHeigt { get; set; }
[JsonProperty("average_fps")]
public double AverageFps { get; set; }
[JsonProperty("delay")]
public long Delay { get; set; }
[JsonProperty("createt_at")]
public DateTime CreatetAt { get; set; }
[JsonProperty("is_playlist")]
public bool IsPlaylist { get; set; }
[JsonProperty("stream_type")]
public string StreamType { get; set; }
[JsonProperty("preview")]
public StreamPreview Preview { get; set; }
[JsonProperty("channel")]
public Channel channel { get; set; }
}
class StreamPreview
{
[JsonProperty("small")]
public string SmallPreview { get; set; }
[JsonProperty("medium")]
public string MediumPreview { get; set; }
[JsonProperty("large")]
public string LargPreview { get; set; }
[JsonProperty("template")]
public string TemplatePreview { get; set; }
}
public class Channel
{
[JsonProperty("mature")]
public bool Mature { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
[JsonProperty("broadcaster_language")]
public string BroadcasterLanguage { get; set; }
[JsonProperty("display_name")]
public string DisplayName { get; set; }
[JsonProperty("game")]
public string Game { get; set; }
[JsonProperty("language")]
public string Language { get; set; }
[JsonProperty("_id")]
public string ID { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("created_at")]
public DateTime CreatedAt { get; set; }
[JsonProperty("updated_at")]
public DateTime UpdatedAt { get; set; }
[JsonProperty("partner")]
public bool Partner { get; set; }
[JsonProperty("logo")]
public string Logo { get; set; }
[JsonProperty("video_banner")]
public string VideoBanner { get; set; }
[JsonProperty("profile_banner")]
public string ProfileBanner { get; set; }
[JsonProperty("profile_banner_background_color")]
public string ProfileBannerBackgroundColor { get; set; }
[JsonProperty("url")]
public string Url { get; set; }
[JsonProperty("views")]
public long Views { get; set; }
[JsonProperty("followers")]
public long Followers { get; set; }
[JsonProperty("broadcaster_type")]
public string BroadcastType { get; set; }
[JsonProperty("stream_key")]
public string StreamKey { get; set; }
[JsonProperty("email")]
public string Email { get; set; }
}
1) use JSON Utils (https://jsonutils.com/) to generate your C# classes (for attributes select JsonProperty)
2) Newtonsoft.Json is pretty much the standard best library to work with JSON formats in .NET, you can get it from nuget.
3) The code should look something like this, and deserialization should work without any problems:
class Program
{
private static void Main(string[] args)
{
var myObj = JsonConvert.DeserializeObject<JsonDef>(json);
Console.Read();
}
}
public class Preview
{
[JsonProperty("small")]
public string small { get; set; }
[JsonProperty("medium")]
public string medium { get; set; }
[JsonProperty("large")]
public string large { get; set; }
[JsonProperty("template")]
public string template { get; set; }
}
public class Channel
{
[JsonProperty("mature")]
public bool mature { get; set; }
[JsonProperty("status")]
public string status { get; set; }
[JsonProperty("broadcaster_language")]
public string broadcaster_language { get; set; }
[JsonProperty("display_name")]
public string display_name { get; set; }
[JsonProperty("game")]
public string game { get; set; }
[JsonProperty("language")]
public string language { get; set; }
[JsonProperty("_id")]
public int _id { get; set; }
[JsonProperty("name")]
public string name { get; set; }
[JsonProperty("created_at")]
public DateTime created_at { get; set; }
[JsonProperty("updated_at")]
public DateTime updated_at { get; set; }
[JsonProperty("partner")]
public bool partner { get; set; }
[JsonProperty("logo")]
public string logo { get; set; }
[JsonProperty("video_banner")]
public string video_banner { get; set; }
[JsonProperty("profile_banner")]
public string profile_banner { get; set; }
[JsonProperty("profile_banner_background_color")]
public string profile_banner_background_color { get; set; }
[JsonProperty("url")]
public string url { get; set; }
[JsonProperty("views")]
public int views { get; set; }
[JsonProperty("followers")]
public int followers { get; set; }
[JsonProperty("broadcaster_type")]
public string broadcaster_type { get; set; }
[JsonProperty("description")]
public string description { get; set; }
}
public class Stream
{
[JsonProperty("_id")]
public long _id { get; set; }
[JsonProperty("game")]
public string game { get; set; }
[JsonProperty("broadcast_platform")]
public string broadcast_platform { get; set; }
[JsonProperty("community_id")]
public string community_id { get; set; }
[JsonProperty("community_ids")]
public IList<string> community_ids { get; set; }
[JsonProperty("viewers")]
public int viewers { get; set; }
[JsonProperty("video_height")]
public int video_height { get; set; }
[JsonProperty("average_fps")]
public double average_fps { get; set; }
[JsonProperty("delay")]
public int delay { get; set; }
[JsonProperty("created_at")]
public DateTime created_at { get; set; }
[JsonProperty("is_playlist")]
public bool is_playlist { get; set; }
[JsonProperty("stream_type")]
public string stream_type { get; set; }
[JsonProperty("preview")]
public Preview preview { get; set; }
[JsonProperty("channel")]
public Channel channel { get; set; }
}
public class JsonDef
{
[JsonProperty("stream")]
public Stream stream { get; set; }
}
It's because of the DateTime format of the JSON. It is not in a well-formed .Net DateTime. so you can get it as a string and then convert it the way you want or change its format into a readable .Net one.
I'm having some issues handling a JSON array, Here is what I've tried. I have tried also using <List<jsonResponse.RootObect> and get the same result.
I'm using JSON.NET
C#:
jsonResponse.RootObject deserializedResponse = JsonConvert.DeserializeObject<jsonResponse.RootObject>(Globals.jsonResponse);
CLASS:
namespace QuantumView
{
[JsonObjectAttribute]
class jsonResponse
{
public class TransactionReference
{
public string CustomerContext { get; set; }
}
public class Response
{
public TransactionReference TransactionReference { get; set; }
public string ResponseStatusCode { get; set; }
public string ResponseStatusDescription { get; set; }
}
public class SubscriptionStatus
{
public string Code { get; set; }
public string Description { get; set; }
}
public class StatusType
{
public string Code { get; set; }
public string Description { get; set; }
}
public class Address
{
public string AddressLine1 { get; set; }
public string City { get; set; }
public string StateProvinceCode { get; set; }
public string PostalCode { get; set; }
public string CountryCode { get; set; }
}
public class Shipper
{
public string Name { get; set; }
public string ShipperNumber { get; set; }
public Address Address { get; set; }
}
public class Address2
{
public string ConsigneeName { get; set; }
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string City { get; set; }
public string StateProvinceCode { get; set; }
public string PostalCode { get; set; }
public string CountryCode { get; set; }
}
public class ShipTo
{
public string AttentionName { get; set; }
public string PhoneNumber { get; set; }
public Address2 Address { get; set; }
}
public class ReferenceNumber
{
public string Number { get; set; }
public string Value { get; set; }
}
public class Service
{
public string Code { get; set; }
}
public class Activity
{
public string Date { get; set; }
public string Time { get; set; }
}
public class Dimensions
{
public string Length { get; set; }
public string Width { get; set; }
public string Height { get; set; }
}
public class UnitOfMeasurement
{
public string Code { get; set; }
}
public class DimensionalWeight
{
public UnitOfMeasurement UnitOfMeasurement { get; set; }
public string Weight { get; set; }
}
public class PackageWeight
{
public string Weight { get; set; }
}
public class ReferenceNumber2
{
public string Number { get; set; }
public string Value { get; set; }
}
public class PackageServiceOptions
{
public string COD { get; set; }
}
[JsonArray]
public class Package
{
public Activity Activity { get; set; }
public Dimensions Dimensions { get; set; }
public DimensionalWeight DimensionalWeight { get; set; }
public PackageWeight PackageWeight { get; set; }
public string TrackingNumber { get; set; }
public List<ReferenceNumber2> ReferenceNumber { get; set; }
public PackageServiceOptions PackageServiceOptions { get; set; }
}
public class BillToAccount
{
public string Option { get; set; }
public string Number { get; set; }
}
[JsonArray]
public class Manifest
{
public Shipper Shipper { get; set; }
public ShipTo ShipTo { get; set; }
public List<ReferenceNumber> ReferenceNumber { get; set; }
public Service Service { get; set; }
public string PickupDate { get; set; }
public string ScheduledDeliveryDate { get; set; }
public string ScheduledDeliveryTime { get; set; }
public string DocumentsOnly { get; set; }
public Package Package { get; set; }
public string ShipmentChargeType { get; set; }
public BillToAccount BillToAccount { get; set; }
}
public class SubscriptionFile
{
public string FileName { get; set; }
public StatusType StatusType { get; set; }
public List<Manifest> Manifest { get; set; }
public object Origin { get; set; }
}
This is where I'm getting the error..
[JsonArray]
public class SubscriptionEvents
{
public string Name { get; set; }
public string Number { get; set; }
public SubscriptionStatus SubscriptionStatus { get; set; }
public List<SubscriptionFile> SubscriptionFile { get; set; }
}
public class QuantumViewEvents
{
public string SubscriberID { get; set; }
public SubscriptionEvents SubscriptionEvents { get; set; }
}
public class QuantumViewResponse
{
public Response Response { get; set; }
public QuantumViewEvents QuantumViewEvents { get; set; }
public string Bookmark { get; set; }
}
public class RootObject
{
public QuantumViewResponse QuantumViewResponse { get; set; }
}
}
}
The problem was with my class not having the correct properties, it also turns out that the UPS api doesn't send a static type response and it can be different each time.. requiring a new class to deserialize into. I have not found a way to make the class flexible
I deserialize complex JSON (Spotify Playlist) and get root level values but I cannot get branches values. I Google problem, try different options without success but, I assume its silly mistake or lack of knowledge so therefore just ask for help what I am missing?
My classes are:
public class Playlist
{
public string collaborative { get; set; }
public string description { get; set; }
//public <ExternalUrls> external_urls { get; set; } //object
//public List<Followers> followers { get; set; } //object
public string href { get; set; }
public string id { get; set; }
//public List<Image> images { get; set; } //array
public string name { get; set; }
}
public class Tracks
{
public string href { get; set; }
public Item items { get; set; } //object
public string limit { get; set; }
public string next { get; set; }
public string offset { get; set; }
public string previous { get; set; }
public string total { get; set; }
}
And code to deserialize looks like that:
StreamReader responseFromServer = new StreamReader(myWebResponse.GetResponseStream());
var dataResponse = responseFromServer.ReadToEnd();
responseFromServer.Close();
var elements = new JavaScriptSerializer().Deserialize<Playlist>(dataResponse);
RootBuffer.AddRow();
RootBuffer.collaborative = elements.collaborative.ToString();
foreach (Tracks trs in elements.tracks)
{
TracksBuffer.AddRow();
TracksBuffer.href = trs.href.ToString()
}
I genereated the classes using this excellent site: json2csharp.com
And used your existing deserialization code successfully with the following classes. It populated all the data including the child collections (brace yourself, it's a long one):
public class Playlist
{
public bool collaborative { get; set; }
public string description { get; set; }
public ExternalUrls external_urls { get; set; }
public Followers followers { get; set; }
public string href { get; set; }
public string id { get; set; }
public List<Image> images { get; set; }
public string name { get; set; }
public Owner owner { get; set; }
public bool #public { get; set; }
public string snapshot_id { get; set; }
public Tracks tracks { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class ExternalUrls
{
public string spotify { get; set; }
}
public class Followers
{
public object href { get; set; }
public int total { get; set; }
}
public class Image
{
public object height { get; set; }
public string url { get; set; }
public object width { get; set; }
}
public class ExternalUrls2
{
public string spotify { get; set; }
}
public class Owner
{
public ExternalUrls2 external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class ExternalUrls3
{
public string spotify { get; set; }
}
public class AddedBy
{
public ExternalUrls3 external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class ExternalUrls4
{
public string spotify { get; set; }
}
public class Image2
{
public int height { get; set; }
public string url { get; set; }
public int width { get; set; }
}
public class Album
{
public string album_type { get; set; }
public List<object> available_markets { get; set; }
public ExternalUrls4 external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public List<Image2> images { get; set; }
public string name { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class ExternalUrls5
{
public string spotify { get; set; }
}
public class Artist
{
public ExternalUrls5 external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public string name { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class ExternalIds
{
public string isrc { get; set; }
}
public class ExternalUrls6
{
public string spotify { get; set; }
}
public class Track
{
public Album album { get; set; }
public List<Artist> artists { get; set; }
public List<object> available_markets { get; set; }
public int disc_number { get; set; }
public int duration_ms { get; set; }
public bool #explicit { get; set; }
public ExternalIds external_ids { get; set; }
public ExternalUrls6 external_urls { get; set; }
public string href { get; set; }
public string id { get; set; }
public string name { get; set; }
public int popularity { get; set; }
public string preview_url { get; set; }
public int track_number { get; set; }
public string type { get; set; }
public string uri { get; set; }
}
public class Item
{
public string added_at { get; set; }
public AddedBy added_by { get; set; }
public bool is_local { get; set; }
public Track track { get; set; }
}
public class Tracks
{
public string href { get; set; }
public List<Item> items { get; set; }
public int limit { get; set; }
public object next { get; set; }
public int offset { get; set; }
public object previous { get; set; }
public int total { get; set; }
}
Hope this helps.
I am using .net to call to a webservice then parse it to usable data.
Right now I am experimenting with this call: http://www.reddit.com/r/all.json
Which returns: http://pastebin.com/AbV4yVuC
This is put in to a string, which I called jsontxt.
I am using JSON.NET to parse the information but it doesn't seem to be working. I initially tried to deserialize it as an object and it didn't work as nothing is put in to the variable
Then I tried to deserialize it as a dataset and I'm having no luck again. My error was
An unhandled exception of type 'Newtonsoft.Json.JsonException' occurred in Newtonsoft.Json.dll
MY CODE:
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace tutorialresult1
{
class Program
{
static void Main(string[] args)
{
using (var webClient = new System.Net.WebClient())
{
var jsontxt = webClient.DownloadString("http://www.reddit.com/r/all.json");
// Console.Write(json);
// -----Deserializing by Object--------------
//MediaEmbed account = JsonConvert.DeserializeObject<MediaEmbed>(jsontxt);
//Console.WriteLine(account.width); //COMES OUT TO NULL
// -----Deserializing by DataSet--------------
DataSet dataSet = JsonConvert.DeserializeObject<DataSet>(jsontxt);
DataTable dataTable = dataSet.Tables["Children"];
Console.WriteLine(dataTable.Rows.Count);
}
}
public class MediaEmbed
{
public string content { get; set; }
public int width { get; set; }
public bool scrolling { get; set; }
public int height { get; set; }
}
.... //rest of classes here for each json which were generated with http://json2csharp.com/
}
}
I'm just trying to make the JSON easily accessible by parsing it.
Using json2charp I generated the following set of classes. Using those you should be able to deserialize the JSON into RootObject using JSON.NET.
var account = JsonConvert.DeserializeObject<RootObject>(jsontxt);
.
public class MediaEmbed
{
public string content { get; set; }
public int? width { get; set; }
public bool? scrolling { get; set; }
public int? height { get; set; }
}
public class Oembed
{
public string provider_url { get; set; }
public string description { get; set; }
public string title { get; set; }
public string url { get; set; }
public string type { get; set; }
public string author_name { get; set; }
public int height { get; set; }
public int width { get; set; }
public string html { get; set; }
public int thumbnail_width { get; set; }
public string version { get; set; }
public string provider_name { get; set; }
public string thumbnail_url { get; set; }
public int thumbnail_height { get; set; }
public string author_url { get; set; }
}
public class SecureMedia
{
public Oembed oembed { get; set; }
public string type { get; set; }
}
public class SecureMediaEmbed
{
public string content { get; set; }
public int? width { get; set; }
public bool? scrolling { get; set; }
public int? height { get; set; }
}
public class Oembed2
{
public string provider_url { get; set; }
public string description { get; set; }
public string title { get; set; }
public int thumbnail_width { get; set; }
public int height { get; set; }
public int width { get; set; }
public string html { get; set; }
public string version { get; set; }
public string provider_name { get; set; }
public string thumbnail_url { get; set; }
public string type { get; set; }
public int thumbnail_height { get; set; }
public string url { get; set; }
public string author_name { get; set; }
public string author_url { get; set; }
}
public class Media
{
public string type { get; set; }
public Oembed2 oembed { get; set; }
}
public class Data2
{
public string domain { get; set; }
public object banned_by { get; set; }
public MediaEmbed media_embed { get; set; }
public string subreddit { get; set; }
public string selftext_html { get; set; }
public string selftext { get; set; }
public object likes { get; set; }
public SecureMedia secure_media { get; set; }
public string link_flair_text { get; set; }
public string id { get; set; }
public int gilded { get; set; }
public SecureMediaEmbed secure_media_embed { get; set; }
public bool clicked { get; set; }
public bool stickied { get; set; }
public string author { get; set; }
public Media media { get; set; }
public int score { get; set; }
public object approved_by { get; set; }
public bool over_18 { get; set; }
public bool hidden { get; set; }
public string thumbnail { get; set; }
public string subreddit_id { get; set; }
public object edited { get; set; }
public string link_flair_css_class { get; set; }
public object author_flair_css_class { get; set; }
public int downs { get; set; }
public bool saved { get; set; }
public bool is_self { get; set; }
public string permalink { get; set; }
public string name { get; set; }
public double created { get; set; }
public string url { get; set; }
public object author_flair_text { get; set; }
public string title { get; set; }
public double created_utc { get; set; }
public int ups { get; set; }
public int num_comments { get; set; }
public bool visited { get; set; }
public object num_reports { get; set; }
public object distinguished { get; set; }
}
public class Child
{
public string kind { get; set; }
public Data2 data { get; set; }
}
public class Data
{
public string modhash { get; set; }
public List<Child> children { get; set; }
public string after { get; set; }
public object before { get; set; }
}
public class RootObject
{
public string kind { get; set; }
public Data data { get; set; }
}
You are trying to deserialize a json-string into a dataset-object. But the json-string doesn't have the format of a dataset. So you need to create a class which matches the json or deserialize it into a dictionary or sth. like this.
Have you tried deserialize using the following? Seems to be more robust for me.
using System.Web.Script.Serialization;
...
var x = new JavaScriptSerializer().Deserialize<Obj_type>(jsonstring);
http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer%28v=vs.110%29.aspx
as purplej0kr mentioned you will need to have a .Net model to use for Obj_type (and it will need to match the object you are parsing) or this will not work.
You will need the System.Web.Extensions.dll referenced in your project (right click add reference, dll is usually under 'Assemblies'). Otherwise:
Where can I find the assembly System.Web.Extensions dll?