C# 如何在c中解析JSON(数组数据)
我正在将JSON数据发送到asp.net,但我无法读取其中的内容。我想要的是将JSON数组值作为密钥对数据读取 voidcheckWithServer:NSDictionary*数据{ //创建请求后有效负载C# 如何在c中解析JSON(数组数据),c#,ios,objective-c,C#,Ios,Objective C,我正在将JSON数据发送到asp.net,但我无法读取其中的内容。我想要的是将JSON数组值作为密钥对数据读取 voidcheckWithServer:NSDictionary*数据{ //创建请求后有效负载 NSDictionary *tmp = [[NSDictionary alloc]initWithObjectsAndKeys: @"user/login",@"routeFunc",data, @"data",
NSDictionary *tmp = [[NSDictionary alloc]initWithObjectsAndKeys:
@"user/login",@"routeFunc",data, @"data",
nil];
NSError *error;
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
NSData *postdata = [NSJSONSerialization dataWithJSONObject:tmp options:0 error:&error];
NSString *serverURL = baseURLDefault;
// Create the POST request to the server.
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:serverURL]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%d", [postdata length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postdata];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSLog(@"%@",[[request URL]absoluteString]);
[conn start];
[NSURLConnection sendAsynchronousRequest: request
queue: queue
completionHandler: ^(NSURLResponse *response, NSData *data, NSError *error) {
if (error || !data) {
NSLog(@"sonuc %@ %@",error,data);
} else {
NSError *parseError = nil;
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSDictionary *dic = [httpResponse allHeaderFields];
NSLog(@"%@ %@",dic,dictionary);
if (!dictionary) {
NSLog(@"%s: JSONObjectWithData error: %@; data = %@", __FUNCTION__, parseError, [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
return;
}
}
}
];
}
我试着读这个,但没用
var dict = new Dictionary<string, string>();
foreach (string key in Request.QueryString.Keys)
{
dict.Add(key,Request.QueryString[key]);
}
string json = new JavaScriptSerializer().Serialize(dict);
Response.ContentType = "text/plain";
Response.Write(json);
您好@user3236289,您将数据发布在请求正文中,您无法通过request.QueryString读取。请完整发布您的方法后端C代码。var dict=new Dictionary;request.QueryString.Keys中的foreach字符串键{dict.Addkey,request.QueryString[key];}string json=new JavaScriptSerializer.Serializedict;Response.ContentType=text/plain;Response.Writejson;这也是不工作的JObject data=JObject.ParseRequest.QueryString[data];