1) add namespaces
using System.Web.Script.Serialization;
using System.Runtime.Serialization.Json;
2)my json string is like this in that i have two objects
1)_ReachOut
2) userDetails
and one array name is reachoutfactorsList
var datalist={“_ReachOut”:{“reachoutid”:65,”user_ID”:100,”question”:”reaching out about”,”anonymous”:false,”shared”:true,”create_date”:”\/Date(1345772377607)\/”,”update_date”:”\/Date(1346040165280)\/”,”status”:1,”start_date”:”\/Date(-62135596800000)\/”,”end_Date”:”\/Date(-62135596800000)\/”,”reachoutfactorsList”:[{“reachoutid”:0,”factor_ID”:373,”orders”:0,”description”:”p”,”preachOutID”:0,”pfactor_ID”:373,”porders”:0,”pdescription”:”p”},{“reachoutid”:0,”factor_ID”:374,”orders”:0,”description”:”q”,”preachOutID”:0,”pfactor_ID”:374,”porders”:0,”pdescription”:”q”},{“reachoutid”:0,”factor_ID”:375,”orders”:0,”description”:”r”,”preachOutID”:0,”pfactor_ID”:375,”porders”:0,”pdescription”:”r”},{“reachoutid”:0,”factor_ID”:376,”orders”:0,”description”:”s”,”preachOutID”:0,”pfactor_ID”:376,”porders”:0,”pdescription”:”s”}],”reachoutchoicesList”:[{“choice_ID”:1,”orders”:1,”description”:”s”,”detail”:null,”rouserid”:0,”reachOutID”:0,”getChoiceData”:null,”mediaURL”:null,”_arrayReachOutChoice”:null,”mediaURL_AttachmentID”:null,”pchoice_ID”:1,”porders”:1,”pdescription”:”s”},{“choice_ID”:2,”orders”:2,”description”:”d”,”detail”:null,”rouserid”:0,”reachOutID”:0,”getChoiceData”:null,”mediaURL”:null,”_arrayReachOutChoice”:null,”mediaURL_AttachmentID”:null,”pchoice_ID”:2,”porders”:2,”pdescription”:”d”},{“choice_ID”:3,”orders”:3,”description”:”f”,”detail”:null,”rouserid”:0,”reachOutID”:0,”getChoiceData”:null,”mediaURL”:null,”_arrayReachOutChoice”:null,”mediaURL_AttachmentID”:null,”pchoice_ID”:3,”porders”:3,”pdescription”:”f”},{“choice_ID”:4,”orders”:4,”description”:”sd”,”detail”:null,”rouserid”:0,”reachOutID”:0,”getChoiceData”:null,”mediaURL”:null,”_arrayReachOutChoice”:null,”mediaURL_AttachmentID”:null,”pchoice_ID”:4,”porders”:4,”pdescription”:”sd”},{“choice_ID”:5,”orders”:5,”description”:”dfd”,”detail”:null,”rouserid”:0,”reachOutID”:0,”getChoiceData”:null,”mediaURL”:null,”_arrayReachOutChoice”:null,”mediaURL_AttachmentID”:null,”pchoice_ID”:5,”porders”:5,”pdescription”:”dfd”},{“choice_ID”:6,”orders”:6,”description”:”werte”,”detail”:null,”rouserid”:0,”reachOutID”:0,”getChoiceData”:null,”mediaURL”:null,”_arrayReachOutChoice”:null,”mediaURL_AttachmentID”:null,”pchoice_ID”:6,”porders”:6,”pdescription”:”werte”}],”detail”:”<p>Give us some details Give us some details</p>”,”set_Listof_Tags”:null,”tag”:{“similarTag”:null,”_TagID”:0,”_TagText”:null,”_TagType”:null},”get_Listof_Tags”:null,”goal”:”Be happy”,”Title”:”reaching-out-about-65″,”reachouttag”:null,”arrayOfreachouttag”:null,”haveliked”:false,”showcountoflike”:”0″,”Reachout_Like_Punch_Retry_date”:””,”finalchoiceid”:0,”finalchoicedesc”:null,”finalchoicename”:null},”userDetails”:{“emailid”:”a@a.com”,”password”:”M40FsP+6CcI=”,”firstname”:”Amar”,”lastname”:”Kumar”,”initials”:null,”age”:”25″,”dob”:”\/Date(528661800000)\/”,”gender”:”M”,”create_date”:”\/Date(1332916788510)\/”,”update_date”:”\/Date(1345464704810)\/”,”status”:1,”facebookuser”:true,”roleid”:1,”FacebookID”:null,”ThumImage”:””,”Image”:””,”addressid”:0,”userid”:100,”address1″:null,”address2″:null,”city”:null,”po_box”:0,”zip”:0,”statecode”:null,”countrycode”:null,”IsActive_Facebook”:0,”Attachments_ID”:0,”TimeZone”:null,”Location”:”pune”,”aboutyourself”:”What makes Amar tick?”,”ProfileComplete”:1,”quote”:”Hi I am Shailesh Sahu “,”profileimageurl”:”https://lh5.googleusercontent.com/-DZgr7J9D6xM/UCiD50ANpRI/AAAAAAAAEPs/VxQLI4sMVdU/s75/Shailesh-Aug2012.jpg”,”titleUserName”:”amarkumar-100″,”addresscreate_date”:”\/Date(-62135596800000)\/”,”addressupdate_date”:”\/Date(-62135596800000)\/”,”alreadyhavetuned”:false,”Twitter_User”:false,”TwitterID”:null,”IsActive_Twitter”:0,”ActivationNumber”:null,”ActivationCode”:null,”ActivationID”:0,”PicasaAlbumID”:0,”FacebookOfflineToken”:null,”TwitterOfflineToken”:null,”TwitterScreenName”:null,”TwitteruserAccessToken”:null,”TwitteruserAccessSecret”:null,”UserFacebookID”:null,”FriendFacebookID”:null,”FriendName”:null,”FriendPictureURL”:null,”Love”:0,”following”:4,”follower”:2,”Punched”:0,”Retry”:0,”Thanked”:0,”BulkDataTableName”:null,”BulkTableName”:null,”EmailNotification”:1},”actType”:”RO”,”userActivitiesList”:null}
3) accessing values from datalist
foreach (var data in datalist)
{
string[] matchstr = data.ToString().Split(‘:’);
matchstr = matchstr[0].ToString().Split(‘\”‘);
var json = data.ToString();
var jss = new JavaScriptSerializer();
var table = jss.Deserialize<dynamic>(json);
if (matchstr[1].ToString() == “_ReachOut”) //RO
{
var RoChoiceLst = table[“_ReachOut”][“reachoutchoicesList”]; // assining array values to variable
foreach (var nRoChoiceLst in RoChoiceLst) //accessing array variable values one by one
{
rochlist += Convert.ToString(nRoChoiceLst[“porders”]);
}
reachoutStrip +=table[“userDetails”][“lastname”] //accessing “lastname” values form userDetails object
reachoutStrip+=table[“_ReachOut”][“question”]; // accessing “question” values form ReachOut object
}
}