【问题标题】:Posting NSArray using ASIFormDataRequest but json format gets changed it appends \n使用 ASIFormDataRequest 发布 NSArray 但 json 格式被更改它附加 \n
【发布时间】:2013-10-08 12:48:51
【问题描述】:

我真的需要解决这个问题,我通过创建请求使用 ASIHTTPRequest 发布了一个带有少量参数的数组:

{
categories={
    attributes=({
        id=1;values=();
    });categories=({
        id=9;values=({
            id=28;
        });
    });
};description=dfsvdsfs;id=0;localid=1;originalid=0;remarks="";sections=();title=Hhhh;} 

但是当我在服务器端以 json 格式发布它时,它会被更改并在数组之间添加 \n :

{
"sections": "(\n)",
"categories": "{\n 
 attributes = (\n {\n id = 1;\n 
 values = (\n );\n }\n );\n 
 categories = (\n {\n id = 9;\n 
 values = (\n {\n id = 28;\n }\n );\n }\n 
);\n}",
 "id": "0",
"originalid": "0",
"localid": "1",
"title": "Hhhh",
"description": "dfsvdsfs",
"remarks": ""
}

请建议我应该做什么?

我尝试使用 :

删除 \n

[value stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];

【问题讨论】:

    标签: iphone objective-c json asihttprequest asiformdatarequest


    【解决方案1】:

    这样试试,

    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:objcts
              options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    

    其中 objcts= 你的数组

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多