Eels Fan
Eels Fan

Reputation: 2063

Parse JSON with .NET 2.0

I have an app written in C# with version 2.0 of the .NET Framework. Unfortunately, I do NOT have the option of updating to a newer version of .NET.

My app is calling a webservice that returns some JSON. The returned JSON looks something like the following:

{"Status":1, "ID":"12345"}

I need parse this string and get the respective Status and ID values. If I was using a later version of the .NET framework, I would use the System.Json namespace. However, I do not have that luxury. I have no idea how to parse this response.

Does anyone know how I can parse this with C# in .NET 2.0?

Upvotes: 9

Views: 25200

Answers (6)

Akash Gaikwad
Akash Gaikwad

Reputation: 11

For .net 2.0 you can you use Newtonsoft.Json and can parse like this JsonConvert.DeserializeObject<yourobject>(jsonString);

Upvotes: -1

Tal Aloni
Tal Aloni

Reputation: 1519

I was able to backport Mono's implementation of System.Json to C# 2.0 with a few minor changes.

You'll need 6 files from here or you can simply download my C# 2.0 project from here.

Upvotes: 1

St&#233;phane B.
St&#233;phane B.

Reputation: 3270

Unfortunately JSON.NET isn't adapted for .NET Compact Framework 2.0.

I'm using Json for the Compact Framework.

public class YourClass {        
  public int Status = 0;
  public String ID = "";
}

using CodeBetter.Json;

YourClass object = Converter.Deserialize<YourClass >(jsonString);

Upvotes: 1

Jeff
Jeff

Reputation: 12163

Yes, James Newton-King's JSON.NET supports .NET 2.0, and is fairly simple to work with.

I have used it numerous times, where .NET's JavaScriptSerializer just didn't cut it.

Upvotes: 14

Justin Pihony
Justin Pihony

Reputation: 67075

You should be able to use JSON.NET and here is the article describing this

Upvotes: 1

Willem D&#39;Haeseleer
Willem D&#39;Haeseleer

Reputation: 20180

you can, and should, do that with this library http://james.newtonking.com/pages/json-net.aspx

Upvotes: 3

Related Questions