8/24/11

How to Parse JSON Using C# .Net

There are a few libraries you can use to parse json but they can be a pain to initialize and setup when all you need is to grab a specific value given a parameter name and you don't have an array of data.


Here's a function I use for the above scenario:






private string ParseJSON(string getField, string jsonData)
{
string returnValue = "";

returnValue = jsonData.Substring((jsonData.IndexOf(getField) + getField.Length + 3));
if(returnValue.IndexOf(",")<0)
returnValue = returnValue.Substring(0, returnValue.IndexOf("}") - 1);
else
returnValue = returnValue.Substring(0, returnValue.IndexOf(",") - 1);


return returnValue;

}

9 comments:

  1. Thanks a lot for sharing this with all of us, I like it and we can communicate. Do you need buy app ratings and reviews. To boost app ranking and double app downloads now.

    ReplyDelete
  2. We find lots of learning after reading this very useful article . cara menggugurkan hamil

    ReplyDelete