Sto cercando di pubblicare un oggetto JSON su un servizio web asp.net.
Il mio json si presenta così:
var markers = { "markers": [
{ "position": "128.3657142857143", "markerPosition": "7" },
{ "position": "235.1944023323615", "markerPosition": "19" },
{ "position": "42.5978231292517", "markerPosition": "-3" }
]};
Sto usando json2.js per stringyfy il mio oggetto json.
e sto usando jquery per pubblicarlo sul mio servizio web.
$.ajax({
type: "POST",
url: "/webservices/PodcastService.asmx/CreateMarkers",
data: markers,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data){alert(data);},
failure: function(errMsg) {
alert(errMsg);
}
});
Ricevo il seguente errore:
"Primitiva JSON non valida:
Ho trovato un sacco di post relativi a questo e sembra essere un problema molto comune, ma nulla che provo risolva il problema.
Quando si esegue il firebug, ciò che viene pubblicato sul server è simile al seguente:
marcatori% 5B0% 5D% 5Bposition% 5D = 128,3657142857143 & marcatori% 5B0% 5D% 5BmarkerPosition% 5D = 7 & marcatori% 5B1% 5D% 5Bposition% 5D = 235,1944023323615 & marcatori% 5B1% 5D% 5BmarkerPosition% 5D = 19 e marcatori% 5B2% 5D% 5Bposition% 5D = 42,5978231292517 & marcatori% 5B2% 5D% 5BmarkerPosition% 5D = -3
La mia funzione di servizio web che viene chiamata è:
[WebMethod]
public string CreateMarkers(string markerArray)
{
return "received markers";
}