Saturday, 20 April 2019
Tuesday, 16 April 2019
REading json
Use NewtonSoft.Json from nuget
ConStr.Json
.aspx file
ConStr.Json
{ "Connections": [ { "Con1": "Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;" }, { "Con2": "Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;" }, { "Con3": "Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;" } ] }
.aspx file
public partial class ReadJson : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { JObject o1 = JObject.Parse(File.ReadAllText(Server.MapPath("/") + "ConStr.json")); // read JSON directly from a file using (StreamReader file = File.OpenText(Server.MapPath("/") + "ConStr.json")) using (JsonTextReader reader = new JsonTextReader(file)) { JObject o2 = (JObject)JToken.ReadFrom(reader); Response.Write(o2["Connections"][0]["Con1"]); } } }
Subscribe to:
Posts (Atom)