Hello,
As i m new to this technology please suggest me...
I want to parse below json string and store in the model.
The url that I have returns follwing JSON object as:
{
"statusCode":"0",
"statusDescription":"SUCCESS",
"responseContent":{
"WH_COMM_LOC_MAP":[
{
"whCode":"SITWH",
"commodityCode":"RMSEED",
"locationCode":"NMM",
"wspCode":"95012",
"whName":"SIT Warehouse",
"whAddress":"",
"commodityName":"RAPE MUSTARD SEED",
"uom":"MT",
"locName":"Navi Mumbai"
},
{
"whCode":"SITWH",
"commodityCode":"IMPURAD",
"locationCode":"NMM",
"wspCode":"95012",
"whName":"SIT Warehouse",
"whAddress":"",
"commodityName":"IMPORTED URAD",
"uom":"MT",
"locName":"Navi Mumbai"
},
{
"whCode":"SITWH",
"commodityCode":"LMNTUR",
"locationCode":"NMM",
"wspCode":"95012",
"whName":"SIT Warehouse",
"whAddress":"",
"commodityName":"IMPORTED LEMON TUR",
"uom":"MT",
"locName":"Navi Mumbai"
}
],
"HOLIDAY_MSTR":[ ],
"CLIENT_MSTR":[ ]
},
"sessionId":null
}
Shashank PatilPosted Sep 8, 2015, 1:01 AM
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Serialization.Json;
namespace JsonParser
{
class Program
{
static void Main(string[] args)
{
string path = @"D:\json.txt";
MemoryStream jsonObject = new MemoryStream();
using (FileStream fsSource = new FileStream(path,
FileMode.Open, FileAccess.Read))
{
jsonObject.SetLength(fsSource.Length);
fsSource.Read(jsonObject.GetBuffer(), 0, (int)fsSource.Length);
DataContractJsonSerializer jsonObj = new DataContractJsonSerializer(typeof(Output));
Output parameter = (Output)jsonObj.ReadObject(jsonObject);
if(parameter != null)
{
}
}
}
}
public class Output
{
public string statusCode { get; set; }
public string statusDescription { get; set; }
//public string responseContent { get; set; }
public responseContent responseContent { get; set; }
public string sessionId { get; set; }
}
public class responseContent
{
public List
public List
public List
}
public class WH_COMM_LOC_MAP
{
public string whCode { get; set; }
public string commodityCode { get; set; }
public string locationCode { get; set; }
public string wspCode { get; set; }
public string whName { get; set; }
public string whAddress { get; set; }
public string commodityName { get; set; }
public string uom { get; set; }
public string locName { get; set; }
}
public class HOLIDAY_MSTR
{
public string text { get; set; }
}
public class CLIENT_MSTR
{
public string text { get; set; }
}
}
Ratika TamboliPosted Sep 9, 2015, 9:18 AM
Shashank PatilPosted Sep 9, 2015, 2:22 AM
Ratika TamboliPosted Sep 9, 2015, 1:33 AM
Shashank PatilPosted Sep 9, 2015, 1:09 AM
Ratika TamboliPosted Sep 9, 2015, 1:00 AM
Ratika TamboliPosted Sep 8, 2015, 12:54 AM
Shashank PatilPosted Sep 7, 2015, 8:56 AM
{
static void Main(string[] args)
{
string path = @"D:\json.txt";
MemoryStream jsonObject = new MemoryStream();
using (FileStream fsSource = new FileStream(path,
FileMode.Open, FileAccess.Read))
{
jsonObject.SetLength(fsSource.Length);
fsSource.Read(jsonObject.GetBuffer(), 0, (int)fsSource.Length);
string objectOut = Encoding.ASCII.GetString(jsonObject.ToArray());
DataContractJsonSerializer jsonObj = new DataContractJsonSerializer(typeof(Output));
Output parameter = (Output)jsonObj.ReadObject(jsonObject);
}
}
public class Output
{
public string statusCode { get; set; }
public string statusDescription { get; set; }
//public string responseContent { get; set; }
public responseContent responseContent { get; set; }
public string sessionId { get; set; }
}
public class responseContent
{
public List
public List
public List
}
public class WH_COMM_LOC_MAP
{
public string whCode { get; set; }
public string commodityCode { get; set; }
public string locationCode { get; set; }
public string wspCode { get; set; }
public string whName { get; set; }
public string whAddress { get; set; }
public string commodityName { get; set; }
public string uom { get; set; }
public string locName { get; set; }
}
public class HOLIDAY_MSTR
{
public string text { get; set; }
}
public class CLIENT_MSTR
{
public string text { get; set; }
}
Shashank PatilPosted Sep 7, 2015, 7:50 AM
Ratika TamboliPosted Sep 7, 2015, 7:38 AM
Shashank PatilPosted Sep 7, 2015, 6:39 AM
var parameter = (jsonClass[])jsonObj .ReadObject(read the json from url in stream member);