ios - JSON POST Web 服务中的多个 Json 对象和 3 个字符串
<p><p>我正在研究 Post 方法。我有 3 个 json 和 3 个字符串。我想将它们用于发布方法。
我尝试了很多解决方案,但都没有解决。 order_item_details, order_details, device_info 有json对象</p>
<pre><code> NSURL *url=;
NSMutableURLRequest *request = [ init];
;
NSMutableData *jsonData = ;
// add params (all params are strings)
dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
;
forHTTPHeaderField:@"Content-Length"];
// //HTTP Authentication
NSString *authStr = ;
NSData *authData = ;
NSString *authValue = ;
forHTTPHeaderField:@"Authorization"];
;
;
;
NSError *error = [ init];
NSHTTPURLResponse *response = nil;
NSData *urlData=;
if ( >= 200 && < 300)
{
NSString *responseData = [initWithData:urlData encoding:NSUTF8StringEncoding];
SBJsonParser *jsonParser = ;
NSDictionary *jsonData = (NSDictionary *) ;
NSLog(@"%@",jsonData);
}
</code></pre>
<p>作为回应,我得到了空值。我有像下面这样的json</p>
<pre><code> {order_item_details= [{"item_amount":"500.00","item_price":"100.00","item_size":"M","page_name":"Billi","quantity":"5","fk_image_id":880},{"item_amount":"250.00","item_price":"50.00","item_size":"S","page_name":"Billi","quantity":"5","fk_image_id":880}],
order_details=[{"email":"[email protected]","mobile_order_date":"2016-02-11 11:44:16","orderUniqueId":"3204a5eb8be171a51057678233268718302","order_price":"750.00","order_total_amount":"800.00","order_type":"COD","paypal_transaction_id":"","service_charges":"40.00","service_percentage":"5.00","shipping_address":"asad","shipping_cost":"50.0","shipping_name":"asad","shipping_phone":"123456","fk_user_id":141,"no_of_items":2,"order_id":1}],
transaction_id=,
order_unique_id=3204a5eb8be171a51057678233268718302,
user_id=141,
device_info={"device":"klimtwifi","device_model":"SM-T700","device_brand":"samsung","device_id":"LRX22G","device_serial":"3204a5eb8be171a5","device_manufacturer":"samsung","device_product":"klimtwifixx"}}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我已经解决了这个问题,问题是服务器将数据视为一个对象。我已经用下面的代码改变了</p>
<pre><code>NSMutableData *jsonData = ;
dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
dataUsingEncoding:NSUTF8StringEncoding]];
;
</code></pre></p>
<p style="font-size: 20px;">关于ios - JSON POST Web 服务中的多个 Json 对象和 3 个字符串,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/35408138/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/35408138/
</a>
</p>
页:
[1]