Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

posting jquery data

Posted on 2015-01-16
15
Medium Priority
?
156 Views
Last Modified: 2015-01-20
{"Message":"Type \u0027.\u0027 is not supported for deserialization of an array.","StackTrace":"   at System.Web.Script.Serialization.ObjectConverter.ConvertListToObject(IList list, Type type, JavaScriptSerializer serializer, Boolean throwOnError, IList& convertedList)\r\n  

{"AllRequests":[{"Company":"Company","Total":"45","Inventory":"false","First Name":"FName","Last Name":"LName","Street Addr":"Street","Street Addr 2":"","City":"City","State":"AK","Zip":"111111","Email":"email@eamil.com"}]}

Open in new window


$('#btntable').click( function() {
  var table = $('Table#main').tableToJSON();
  var JSONObject = new Object; 
   var item = table;
        JSONObject.AllRequests = item;  
        JSONstring = JSON.stringify(JSONObject); 
  alert(JSONstring);  
   $.ajax({
                type: "POST",
                url: "/rees.aspx/DatatCity",
                data: JSONstring,
                processData: false,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(r) {

Open in new window


         [System.Web.Services.WebMethod]
         public static Detail DatatCity(Detail AllRequests)
         
        {
}
Untitled3.jpg
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
  • 10
  • 5
15 Comments
 
LVL 9

Expert Comment

by:sudheeshthegreat
ID: 40554785
You have a data-type mismatch. The json sent from the client-side and Detail type on the server-side code do not match. The error is due to the server-side code getting an apostrophe/quote character (\u0027) in the serialized json while it is expecting an array.
0
 
LVL 9

Author Comment

by:Seven price
ID: 40554822
How can I fix it
0
 
LVL 9

Expert Comment

by:sudheeshthegreat
ID: 40554838
Can you show us the Detail class definition?
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 9

Author Comment

by:Seven price
ID: 40555165
It's a web method static class.
0
 
LVL 9

Author Comment

by:Seven price
ID: 40555167
WebMethod]
        public string putvalues(string allresults)
        {
            Foreach loop
            // code logic which sets the result value
            result="some value";

            return result;
        }
0
 
LVL 9

Expert Comment

by:sudheeshthegreat
ID: 40557086
You mentioned this
  [System.Web.Services.WebMethod]
         public static Detail DatatCity(Detail AllRequests)
Can you show us how your Detail class is defined?
0
 
LVL 9

Author Comment

by:Seven price
ID: 40558042
0
 
LVL 9

Author Comment

by:Seven price
ID: 40558064
 [WebMethod]
         public static string AddClient(RequestDetail[] AllRequests)
         {
             // TODO: process ...

             // by the way as a result you could also return a strongly 
             // typed model and not only strings 
             // which could be easily manipulated on the client side
             return "some result";
         }

Open in new window

[Table(Name="dbo.RequestDetail")]
	public partial class Detail : INotifyPropertyChanging, INotifyPropertyChanged
	{
		
		private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
		
		private int _DetailID;
		
		private int _RequestID;
		
		private System.Nullable<int> _RequestTotal;
		
		private System.Nullable<bool> _FromInventoryFlag;
		
		private string _Company;
		
		private string _FirstName;
		
		private string _LastName;
		
		private string _StreetAddress;
		
		private string _StreetAddress2;
		
		private string _City;
		
		private string _State;
		
		private string _Zip;
		
		private string _Email;

Open in new window

\
Nothing is working for me.
0
 
LVL 9

Expert Comment

by:sudheeshthegreat
ID: 40558187
From the code you shared, since you have this URL:
"/rees.aspx/DatatCity"

Open in new window

and this json
{"AllRequests":[{"Company":"Company","Total":"45",...

Open in new window

you need to have an array of some type for the AllRequests parameter.
public static Detail DatatCity(Detail[] AllRequests)

Open in new window

And the Detail class here should have public properties for the json you send, such as Company, Total, Inventory and so on.
0
 
LVL 9

Author Comment

by:Seven price
ID: 40558365
not working
[WebMethod]
         public static string AddClient(AllRequests[] AllResults)
         {
             string myself;
             foreach (var c in AllResults)
             {
                 myself = c.Company;
             }

Open in new window

{"AllResults":"[{\"Company\":\"testcompany\"}]"}

Open in new window

public class AllRequests
{
    public string Company { get; set; }
    
}

Open in new window

urrgh why
0
 
LVL 9

Author Comment

by:Seven price
ID: 40558370
{"Message":"Cannot convert object of type \u0027System.String\u0027 to type \u0027AllRequests[]\u0027","StackTrace":"   at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object

Open in new window

0
 
LVL 9

Accepted Solution

by:
sudheeshthegreat earned 1000 total points
ID: 40558392
Is your url for the AJAX call now
"/rees.aspx/AddClient"
instead of
"/rees.aspx/DatatCity"
?
0
 
LVL 9

Author Comment

by:Seven price
ID: 40558413
That part is correct. AddClient is the one I am using. the post in the dom is the json string trying to post. the method will not take it.
0
 
LVL 9

Author Comment

by:Seven price
ID: 40558535
There is something missing. Maybe return as a list umm?
0
 
LVL 9

Author Closing Comment

by:Seven price
ID: 40559729
it was a quote.
{"AllResults":[{"Company":"testcompany"}]}
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

688 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