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 Patil169 reputationPosted Sep 7, 2015, 9:01 PM EDT
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; }
}
}
Shashank Patil169 reputationPosted Sep 8, 2015, 10:22 PM EDT
Shashank Patil169 reputationPosted Sep 7, 2015, 2:39 AM EDT
var parameter = (jsonClass[])jsonObj .ReadObject(read the json from url in stream member);
Ratika Tamboli14 reputationPosted Sep 7, 2015, 3:38 AM EDT
Shashank Patil169 reputationPosted Sep 7, 2015, 3:50 AM EDT
Shashank Patil169 reputationPosted Sep 7, 2015, 4:56 AM EDT
{
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; }
}
Ratika Tamboli14 reputationPosted Sep 7, 2015, 8:54 PM EDT
Ratika Tamboli14 reputationPosted Sep 8, 2015, 9:00 PM EDT
Shashank Patil169 reputationPosted Sep 8, 2015, 9:09 PM EDT
Ratika Tamboli14 reputationPosted Sep 8, 2015, 9:33 PM EDT
Ratika Tamboli14 reputationPosted Sep 9, 2015, 5:18 AM EDT