在iOS中发布JSON值?

在iOS中发布JSON值?,ios,json,Ios,Json,如何使用RESTFUL API发布JSON值 在这里,我添加了一个示例API: http://our.api.com/Search?term=pumas&filters={"productType":["Clothing","Bags"],"color":["Black","Red"]} 我想发布类似上述URL的值并获得响应。是否有任何可能的方法获取值?它是否有示例API?请尝试以下代码 为此,请使用AFNetworking库。链接: 另一种方式 //使用下面的代码请求POST方法。它

如何使用RESTFUL API发布JSON值

在这里,我添加了一个示例API:

http://our.api.com/Search?term=pumas&filters={"productType":["Clothing","Bags"],"color":["Black","Red"]}
我想发布类似上述URL的值并获得响应。是否有任何可能的方法获取值?它是否有示例API?

请尝试以下代码

为此,请使用AFNetworking库。链接:

另一种方式

//使用下面的代码请求POST方法。它很简单

// JSON
NSMutableData   *responseData;
NSURLConnection * Connection_Audio_Upload;
NSMutableURLRequest *request = [NSMutableURLRequest
                                requestWithURL:[NSURL URLWithString:@"http://180.179.227.99/oMomento/webservice.asmx/UploadFileJSon"] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                                timeoutInterval:10];

NSString * params=[NSString stringWithFormat:@"f=%@&step=0&filename=%@.3gp&path=%@",trimmed,audio_File_Name,@"BabyJournal/Audio/"];
[request setHTTPMethod:@"POST"];

[request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
Connection_Audio_Upload=[[NSURLConnection alloc] initWithRequest:request delegate:self];
在.h文件中设置

// JSON
NSMutableData   *responseData;
NSURLConnection * Connection_Audio_Upload;
NSMutableURLRequest *request = [NSMutableURLRequest
                                requestWithURL:[NSURL URLWithString:@"http://180.179.227.99/oMomento/webservice.asmx/UploadFileJSon"] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                                timeoutInterval:10];

NSString * params=[NSString stringWithFormat:@"f=%@&step=0&filename=%@.3gp&path=%@",trimmed,audio_File_Name,@"BabyJournal/Audio/"];
[request setHTTPMethod:@"POST"];

[request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
Connection_Audio_Upload=[[NSURLConnection alloc] initWithRequest:request delegate:self];
在.m文件中设置

// JSON
NSMutableData   *responseData;
NSURLConnection * Connection_Audio_Upload;
NSMutableURLRequest *request = [NSMutableURLRequest
                                requestWithURL:[NSURL URLWithString:@"http://180.179.227.99/oMomento/webservice.asmx/UploadFileJSon"] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                                timeoutInterval:10];

NSString * params=[NSString stringWithFormat:@"f=%@&step=0&filename=%@.3gp&path=%@",trimmed,audio_File_Name,@"BabyJournal/Audio/"];
[request setHTTPMethod:@"POST"];

[request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
Connection_Audio_Upload=[[NSURLConnection alloc] initWithRequest:request delegate:self];
/----使用----JSON方法----/


它是否有关于您的第二个代码的链接。我的JSON格式类似于此url,我发布了此url并希望得到响应。例如:{“productType”:[“衣服”、“包”],“颜色”:[“黑色”、“红色”]}@Imran,您可以使用已编辑的代码使用POST方法实现您的API,&U在ConnectiondFinishLoading方法中获取响应。。我不理解@Mehul我想发布json格式值,而不是像上面url那样的文件。@Imran。。使用like:[NSURL URLWithString:@“our.API.com/Search”]&NSString*参数=[NSString stringWithFormat:@“term=%@&filters=%@”,美洲狮,产品类型];用这些方法实现它。谢谢你的回答@Mehul