Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 2

Just got a job at a securities company's IT department, and I could use some help with JSON and ashx

Solved! Go to Solution.

My colleague gave me an asigment, he want me to set up a IIS localhost then use a .ashx file to send a JSON data to Postman and get result, I'm having a hard time with this because I never used any of this things, and only heard about them, plus the compnay block Youtube so I can't look for tutorial there...
 
The JSON data should be simply like:
{
Uid:'E122605942', //this is userid
startDate:
endDate:  
}
And the result from Postman should be like
{
replyCode:"0", //or replyCode:"99", if userid doesn't exist
replyadvisory:"",
Result: {id
name -->name
nickname: -->name
}

 

I hope I'm making sense, is there anyone can help?

1 Reply
Solution
Copilot Lvl 2
Message 2 of 2

Re: Just got a job at a securities company's IT department, and I could use some help with JSON and

Nevermind, turn out he send me an attachment and I didn't notice, here's what it suppose to be:

 

 
Spoiler
private class results
    {
        public string reply_code { get; set; }
        public string wr_advisory { get; set; }
        public List<user> resultList { get; set; }
    }
 
    public class user
    {
        public string userid { get; set; }
        public string createtime { get; set; }
    }
   
    public void ProcessRequest(HttpContext context)
    {
        List<user> resultLists = new List<user>();
        results rlist = new results();
        user p = null;
        string json = string.Empty;
       
        using (var reader = new System.IO.StreamReader(context.Request.InputStream))
        {
            json = reader.ReadToEnd();
        }
        context.Response.ContentType = "application/json";
        context.Response.Charset = "utf-8";
        p = new JavaScriptSerializer().Deserialize<user>(json);
        

        using (SqlConnection conn = PF.SqlConnection("DBMARKETDATAString"))
        {
            string sSQLCmd = "";
            SqlCommand cmd = new SqlCommand();
            sSQLCmd = @"SELECT [Guid]
                             ,[Uid]
                             ,[Branch]
                             ,[Name]
                             ,[Phone]
                             ,[Seller]
                             ,[Coupon]
                             ,[CreateTime]
                        FROM [MARKET_DATA].[dbo].[AccountApplication]
                        where Uid = (@Uid)
                        or CreateTime = (@Createtime)";

            cmd.Parameters.AddWithValue("@Uid", p.userid);
            cmd.Parameters.AddWithValue("@Createtime", p.createtime);
            try
            {
                cmd.CommandTimeout = 60;
                DataTable dt = PF.ExecuteReader(conn, DataMode.DataTable, ref cmd, sSQLCmd) as DataTable;
                foreach (DataRow LtRow in dt.Rows)
                {
                    resultLists.Add(new user { userid = LtRow["Uid"].ToString(), createtime = LtRow["CreateTime"].ToString() });
                }
                      
                if (resultLists.Count > 0)
                {
                    rlist = new results { reply_code = "0", wr_advisory = "Success", resultList = resultLists };
                    context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(rlist));
                }
                else
                {
                    rlist = new results { reply_code = "999", wr_advisory = "Unsuccess", resultList = null };
                    context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(rlist));
                    return;
                }
            }
            catch (Exception ex)
            {
                rlist = new results { reply_code = "999", wr_advisory = ex.Message, resultList = null };
                context.Response.Write(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(rlist));
            }

        }
      
    }