9

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?

1
  • Can you use third party external libraries in your application? Commented Feb 27, 2013 at 15:47

6 Answers 6

14

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

1

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

Comments

1

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);

Comments

1

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.

2 Comments

That's just a default using statement that you can remove, I have added a link to a C# 2.0 project containing all the necessary files
System.Linq is only used for ToArray() and can easily be removed.
-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.