- I am sending a JSON
request by converting it from an array, to a remote Windows Server 2008 R2, running a .NET
webservice.
- If my JSON
request is successfully executed then i will be replied with a OK
string.
- But i am receving System.InvalidOperationException
.
** Array string:**
(
{
add = "1 Stockton St";
ccode = US;
city = "San Francisco";
country = "United States";
cross = "at Ellis St";
dist = 8;
img = "https://foursquare.com/v/apple-store/42cc7080f964a520e9251fe3";
lang = "-122.4064";
lat = "37.78584";
pcode = 94108;
state = CA;
vid = 42cc7080f964a520e9251fe3;
}
)
Converted JSON String:
[{"city":"San Francisco","add":"1 Stockton St","ccode":"US","vid":"42cc7080f964a520e9251fe3","img":"https://foursquare.com/v/apple-store/42cc7080f964a520e9251fe3","state":"CA","lat":37.78584,"lang":-122.4064,"dist":8,"pcode":"94108","cross":"at Ellis St","country":"United States"}]
Exception thrown from the webserver:
{"Message":"Type \u0027System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]\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 at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
Code for sending:
NSString* jsonString = [newArr JSONRepresentation];
SBJSON *json = [SBJSON new];
json.humanReadable = YES;
responseData = [[NSMutableData data] retain];
NSError *respError = nil;
NSString *service = @"/DerializeDataTable";
NSString *requestString = [NSString stringWithFormat:@"%@",jsonString];
NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]];
NSString *fileLoc = [[NSBundle mainBundle] pathForResource:@"URLName" ofType:@"plist"];
NSDictionary *fileContents = [[NSDictionary alloc] initWithContentsOfFile:fileLoc];
NSString *urlLoc = [fileContents objectForKey:@"URL"];
urlLoc = [urlLoc stringByAppendingString:service];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: urlLoc]];
NSString *postLength = [NSString stringWithFormat:@"%d", [requestData length]];
[request setHTTPMethod: @"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: requestData];
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: &respError ];
if (respError)
{
//error in request
}
else
{
NSString *responseString = [[NSString alloc] initWithData:returnData encoding: NSUTF8StringEncoding];
NSDictionary *results = [[responseString JSONValue] retain];
}
I am not able to detect the problem, i have even tried using SOAP, but still i got the same response... Can anyone please help me out of this... Thank you very much !!