The Simplest way to Parse JSON Data in C# using JSON.Net

SimpleJSONNetExample

using System;
using Newtonsoft.Json.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string json = "{\"employees\": [{ \"firstName\":\"John\" , \"lastName\":\"Doe\" },{ \"firstName\":\"Anna\" , \"lastName\":\"Smith\" }]}";

            JObject o = JObject.Parse(json);
            Console.WriteLine(o["employees"][0]);
            Console.WriteLine(o["employees"][1]["firstName"]);
            Console.WriteLine(o["employees"][1]["lastName"]);
            Console.ReadLine();
        }
    }
}

I was looking for a simple way to parse JSON data using C#, and was led to this example from MSDN: http://msdn.microsoft.com/en-us/library/bb412179(v=vs.110).aspx on how to Serialize and Deserialize JSON Data.  DataContracts, DataMembers, on and on, seemed a bit much for just trying to extract some data from a string.

JSON.net is a library from James Newton-King.  By far the easiest .NET JSON Parser available and according to James, it’s also the fastest.

Resources:
JSON.NET on CodePlex
http://json.codeplex.com/

An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NET
http://msdn.microsoft.com/en-us/library/bb299886.aspx

 

 

Notes on SQLMembership Provider using the MembershipProvider Class

1. Set the tag to use “forms” in the config
2. use the reg_sql to generate the SQL tables for use with SQLMembership Provider.
3. Add 4. Can use membership.createuser(“UN”,”PW”,”Email”) to create user.
5. Methods include:Createuser, ValidateUser, DeleteUser, FinduserByName,finduserByEmail,GenPassword
6.Options to capture other user info with ProfileSystem, and defining provider properties in webconfig. Or simply adding additional tables.

 

[tester]

Table to Excel XLS code

Dim StringWriter1 As IO.StringWriter
Dim StringBuilder1 As StringBuilder = New StringBuilder
StringWriter1 = New IO.StringWriter(StringBuilder1)
Dim TextWriter1 As HtmlTextWriter = New HtmlTextWriter(oStringWriter)
label.RenderControl(oTextWriter)
Response.Clear()
Response.ClearHeaders()
Response.ContentType = “application/vnd.xls”
Response.AddHeader(“Content-Disposition”, “attachment;filename=WLMS-exlfile.xls”)
Response.Write(StringWriter1.ToString())
Response.Flush()
Response.End()

Setting the SelectedValue of RadioButtonList & DropDownList in GridView EditItemTemplate

Here is a trick one, because IntelliSense doesn’t bring up the “SelectedValue” property for a RadioButtonList, or a DropDownList in an EditItemTemplate for GridViews you may forget that “SelectedValue” is an actual property of these controls.

Here is how you can set the selected value of a RadioButtonList inside an EditItemTemplate

[codesyntax lang=”html4strict”]

<asp:TemplateField HeaderText="Payment">
<ItemTemplate>
    <asp:Label ID="lablePayment" runat="server" Text='<%#Eval("PayName")%>' />
</ItemTemplate>
<EditItemTemplate>
  <asp:RadioButtonList Runat = "server" ID="rblPaymentType" SelectedValue='<%#Eval("PayTypeID")%>'>
    <asp:ListItem Text="Check" Value="1"></asp:ListItem>
    <asp:ListItem Text="Credit Card" Value="2"></asp:ListItem>
  </asp:RadioButtonList>
</EditItemTemplate>
</asp:TemplateField>

[/codesyntax]

Compiled Language vs. Interpreted Language

Programming languages generally fall into one of the following categories, Compiled Language or Interpreted Language. Compiled Languages are reduced to a set of machine instructions before being saved as an executable file. In general, a compiled program will execute faster thatn an interpreted program because the Interpreted program must be reduced to machine language at runtime.

Interpreted languages that code is saved in the same format and developed in. Interpreted languages offer more flexability like modifying themselves by adding or changing functions at runtime. Development time can also be reduced with interpreted languages, because the application dose not need to be compiled before each test.

In theory any language can be compiled or interpreted. The Microsoft .NET language is compiled to Common Intermediate Language (CIL) which is compiled into native machine code.

Entity Framework Links

Mozilla Development Center https://developer.mozilla.org/en/Web_Development 

MSDN – Entity Framework http://msdn.microsoft.com/en-us/library/bb386964.aspx 

Entity Frameworkhttp://naspinski.net/post/Getting-started-with-Linq-To-Entities.aspx 

MSDN – The ADO.NET Entity Frameworkhttp://msdn.microsoft.com/en-us/data/aa937723.aspx 

MSDN – .Net Framework Class Library http://msdn.microsoft.com/en-us/library/ms229335.aspx 

MSDN – Data Development Videos (Entity Framework) – http://msdn.microsoft.com/en-us/data/cc300162.aspx 

MSDN – When to use Linq to SQL vs When to use Linq to Entity – http://msdn.microsoft.com/en-us/library/cc161164.aspx

Eight Entity Framework Tutorials on DataDeveloper.NET – http://thedatafarm.com/blog/data-access/eight-entity-framework-tutorials-on-datadeveloper-net/ 

Application Scenarios (Entity Framework) – http://msdn.microsoft.com/en-us/data/bb738689.aspx 
http://code.msdn.microsoft.com/EFDocSamples2008

XtraReport Bindings

Change[sourcecode language='vb.net']Private WithEvents bindingSource1 As System.Windows.Forms.BindingSource[/sourcecode]

To [sourcecode language='vb.net']Public WithEvents bindingSource1 As System.Windows.Forms.BindingSource[/sourcecode]

Also the bindingSource Datasource needs to be changed in the report code.

[sourcecode language=”vb.net”]Me.bindingSource1.DataSource = GetType(TypeofObject)[/sourcecode]

For the report viewer, again bind the bindingSource Datasource

[sourcecode language=”vb.net”]Dim objects As objects
objects = GetAllObjects()
Dim Report1 As New XtraReport1
Report1.bindingSource1.DataSource = objects
ReportViewer1.Report = Report1[/sourcecode]