Solved

Jquery array receive deserializing error

Posted on 2014-07-23
13
212 Views
Last Modified: 2014-07-24
hi, well i am pretty familar with Serialization but not for c# for deserializing.
from my link to jfiddle I am passing the values to the server side.


On the server side I am trying  to take the values and submit them to a server

 public static string CheckExists(string Threshold, int sec) //Method should be declared as static 
        {


            DataContext db = new DataContext();
            Clear aTransaction = new Clear();
            List<IaTransaction> Threshold = JsonConvert.DeserializeObject<List<aTransaction>>();
            try
            {
               foreach  (var grds in Threshold)
{
              
                aTransaction.APTransactionSecurityTypeID = sec;
                aTransaction.Threshold =  sec;
                db.ClientPreClears.InsertOnSubmit(aTransaction);
                db.SubmitChanges();
}
            }
            catch (Exception ex)
            {
            }
         
            return JsonConvert.SerializeObject(Threshold);

        }

Open in new window


Not totally sure of the syntax but it would be so appreciated.
0
Comment
Question by:sevensnake77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
13 Comments
 
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 167 total points
ID: 40215672
Are you trying to create a web method that takes your JSON object as a whole or as separate parameters (Threshold and sec)?
It seems that C# code above does not compile because Threshold is changed from string to a generic list. (line 7). Is the list the one required to convert to JSON and return it back to the AJAX call?
What is IaTransaction class declaration?

If you could be more specific, the JS ajax code will call the server method and what kind of output you are expecting back from the server method.
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40215811
Well there is no need to return anything I just want to pass the json array objects as a method. I want to loop through the array and send it to the server to insert into a table.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40215871
What kind of web project is this? MVC? Web Forms?
0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
LVL 9

Author Comment

by:sevensnake77
ID: 40215892
web Forms 3.5 frameworks
asp.net
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 333 total points
ID: 40215898
How does this function get invoked by the browser? There must be another method that calls this method. What does that method look like?
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40215904
the button like in the example but it will be a button control.<asp:button runat=server id=btn />
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40215907
if you look at the jfiddle example it will invoke on post.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40215909
OK, but how are you getting the data from the AJAX POST into that method (on the server)?
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40215936
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40215949
data = @"[{""ShiftID"":""2"",""EmpName"":""dsdsfs""},{""ShiftID"":""4"",""EmpName"":""dsdsfd""}]";


ar values = JsonConvert.DeserializeObject<Dictionary<string, string>[]>(data);

Open in new window


Ok since I am getting a lot of questions with questions. I have a simple question. see where it says data in my jfiddle code how can I get data to look like the above when sending my data.  data is called when Deserializobject.
string>[]>(data);
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 333 total points
ID: 40215961
You're getting questions because it's not clear how you are getting the data into your code. Regardless, to answer your latest question, you need to have a data structure that mimics the structure of your JSON:

public class Data
{
    public int ShiftID { get; set; }
    public string EmpName { get; set; }
}

Open in new window


That would take care of the innermost objects, but your root data structure is an array. So you are attempting to deserialize an array of this new data structure above.

e.g.

var data = @"[{""ShiftID"":""2"",""EmpName"":""dsdsfs""},{""ShiftID"":""4"",""EmpName"":""dsdsfd""}]";
var values = JsonConvert.DeserializeObject<Data[]>(data);

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40215980
But I use the jfiddle example to show how I am getting data. if you just try the jfiddle example it will do a popup showing you the objects. passing to a var data it my biggest problem.
http://jsfiddle.net/Nbr7Y/6/

now you have var data with the values static, how can I get my json data to the server side
Instead of
var data = @"[{""ShiftID"":""2"",""EmpName"":""dsdsfs""},{""ShiftID"":""4"",""EmpName"":""dsdsfd""}]";

Open in new window

I want {"Threshold":["343","32","2","1","3"],"sec":["3","32","2","1","3"]}
how can I get each object from this example
0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 40217306
i figured it out.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question