Ios 将嵌套的NSDictionary解析为JSON,并发布到服务器

Ios 将嵌套的NSDictionary解析为JSON,并发布到服务器,ios,objective-c,json,parsing,nsdictionary,Ios,Objective C,Json,Parsing,Nsdictionary,所以我遇到了一个问题,我的服务器请求JSON格式: { "offers" : [ ], "branch_id" : 186, "payment_method" : "C", "cash_amount" : 17, "car_model" : "", "coupon_id" : 0, "car_color" : "", "timer" : 299, "brand_id" : 48, "items" : [ { "id" : 1952,

所以我遇到了一个问题,我的服务器请求JSON格式:

{
  "offers" : [
  ],
  "branch_id" : 186,
  "payment_method" : "C",
  "cash_amount" : 17,
  "car_model" : "",
  "coupon_id" : 0,
  "car_color" : "",
  "timer" : 299,
  "brand_id" : 48,
  "items" : [
    {
      "id" : 1952,
      "options" : {
        "369" : [
          1044
        ],
        "370" : [
          1045
        ]
      },
      "quantity" : 1
    }
  ]
}
此格式需要一些嵌套的nsdicentral&数组,这对我来说不是问题,但当我创建此格式并将其发送到服务器时,我得到的是:

[Object: null prototype] {
    branch_id: '186',
    brand_id: '48',
    car_color: '',
    car_model: '',
    cash_amount: '18',
    coupon_id: '0',
    'items[][id]': '1952',
    'items[][options][369][]': '1044',
    'items[][options][370][]': '1046',
    'items[][quantity]': '1',
    payment_method: 'C',
    timer: '299'
}
我尝试使用以下方法对其进行分析:

NSData *data = [NSJSONSerialization dataWithJSONObject:finalOrder options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonOrder = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
但我还是得到了一个错误的格式,比如:

[Object: null prototype] {
branch_id: '186',
brand_id: '48',
car_color: '',
car_model: '',
cash_amount: '36',
coupon_id: '0',
'items[]': '{\n' +
'    id = 1952;\n' +
'    options =     {\n' +
'        369 =         (\n' +
'            1044\n' +
'        );\n' +
'        370 =         (\n' +
'            1046\n' +
'        );\n' +
'    };\n' +
'    quantity = 2;\n' +
'}',
payment_method: 'C',
timer: '299'
}

错误在哪里?这是客户端错误还是服务器端的解析错误

可能不相关但从不预打印发送到服务器的数据。服务器根本不关心。除了额外的
\n
,我还考虑了预打印的。但是这意味着服务器上的解析有点奇怪。你说的“漂亮打印”是什么意思?我们指的是选项
NSJSONWritingPrettyPrinted
。不传递选项。您应该测试从Postman或curl之类的工具发送您知道有效的JSON(例如,您的示例中的JSON)。如果您的服务器正确地理解了它,那么问题就出在客户端,如果您得到类似的错误结果,那么您已经将客户端从等式中排除,因此您知道这是服务器端的问题。