?
Solved

Jquery array receive deserializing error

Posted on 2014-07-23
13
Medium Priority
?
217 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:Seven price
[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 501 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:Seven price
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
Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

 
LVL 9

Author Comment

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

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 999 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:Seven price
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:Seven price
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:Seven price
ID: 40215936
0
 
LVL 9

Author Comment

by:Seven price
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 999 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:Seven price
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:Seven price
ID: 40217306
i figured it out.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

771 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