c# - json.Net save to file -


i have script saving file sorted, cant code save entry: below

{     "entry": [         { "name": "john" },         { "name": "anna" },         { "name": "peter" }     ] } 

im using json.net, code below needs add entry: name

 string json = jsonconvert.serializeobject(results, formatting.indented);  string path = @"c:\inetpub\wwwroot\json\json.net\results.json";   if (!file.exists(path))  {      file.writealltext(path, json);  }  else  {      file.appendalltext(path, json);  } 

i haven't been able find json code samples, cheers paul

i managed so!

  userinfo results = new userinfo     {         name = request["name"],      };      stringbuilder sb = new stringbuilder();     stringwriter sw = new stringwriter(sb);     jsonwriter jsonwriter = new jsontextwriter(sw);     jsonwriter.formatting = formatting.indented;     jsonwriter.writestartobject();     jsonwriter.writepropertyname("name");     jsonwriter.writevalue(results.name);     jsonwriter.writeendobject();      string json = sw.tostring();     jsonwriter.close();     sw.close();      string path = @"c:\inetpub\wwwroot\json\json.net\results.json";      if (!file.exists(path))     {         file.writealltext(path, json);     }     else     {         file.appendalltext(path, json);     }  }  // create class object hold json value public class userinfo {     public string name { get; set; }  } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -