0

I already have some webmethods receiving 1 or 2 parameters working successfully. What I want to do is sent a json string that can be deserialized into a datatable with multiple rows.

The string looks similar to this: [{"sectionID":12,"order":0},{"sectionID":21,"order":10},{"sectionID":20,"order":20},{"sectionID":22,"order":30},{"sectionID":23,"order":40},{"sectionID":24,"order":50},{"sectionID":25,"order":60}]

I tried to pass it as the the value, but that didn't work. data: {'jsonString:','[{"sectionID":12,"order":0},{"sectionID":21,"order":10},{"sectionID":20,"order":20},{"sectionID":22,"order":30},{"sectionID":23,"order":40},{"sectionID":24,"order":50},{"sectionID":25,"order":60}]'}

I got an error about Invalid object passed in. I then tried this type of method declaration as I saw somewhere: public static void updateSectionPositions(List sectionList) where SectionPosition is a class with 2 properties of sectionID and order. That gives me the same error.

Any ideas? The ultimate goal is to have this json string become a datatable that I can traverse on the c# side. Thanks.

Aaron Bratcher
  • 6,051
  • 2
  • 39
  • 70

1 Answers1

0

Pass it to the webmethod as a string.

Use a server side Json library to deserialize that string into objects.

You should be able to populate a datatable from there.

nunespascal
  • 17,584
  • 2
  • 43
  • 46
  • Trying to send the JSON string as a string value to the webmethod. See where I said "I tried to pass it as the value..." The webmethod was set to receive a string variable called jsonString. – Aaron Bratcher Jul 06 '12 at 10:57
  • Could you share your jsonString? You would have to use some function to serialize it to a string. I have sent very large json string to webmethods without and problems. – nunespascal Jul 06 '12 at 11:02
  • I've since moved on and now have the javascript call the webmethod several times. – Aaron Bratcher Jul 06 '12 at 18:35