zoukankan      html  css  js  c++  java
  • iOS对象(数组)转化为JSon字符串

    - (void)seabc

    {

        NSArray *arry=[NSArray arrayWithObjects:@"0081",@"0082",@"0083", nil];

        NSString *ss = [self objArrayToJSON:arry];

        NSString * datsa = [NSString stringWithFormat:@"pictures=%@",ss];

        NSLog(@"jsonStr==%@",datsa);

     

        NSString *url = [NSString stringWithFormat:@"http://app.y-x-q.cn/index.php/interfaces/Articleapi/test1"];

        

        [RequstHttp postWithPathURL:url params:datsa succes:^(NSData *json) {

            NSLog(@"json:%@",[[NSString alloc]initWithData:json encoding:NSUTF8StringEncoding]);

        } failure:^(NSError *error) {

        }];

        

    }

     

    //把多个json字符串转为一个json字符串

    - (NSString *)objArrayToJSON:(NSArray *)array {

        

        NSString *jsonStr = @"[";

        

        for (NSInteger i = 0; i < array.count; ++i) {

            if (i != 0) {

                jsonStr = [jsonStr stringByAppendingString:@","];

            }

            jsonStr = [jsonStr stringByAppendingString:array[i]];

        }

        jsonStr = [jsonStr stringByAppendingString:@"]"];

        

        return jsonStr;

    }

  • 相关阅读:
    升级linux bash
    vim关键字自动补全
    linux bash shell之变量替换::=句法、=句法、:句法、句法、=?句法、?句法、:+句法、+句法
    使用Bash编写Linux Shell脚本7.复合命令
    使用Bash编写Linux Shell脚本5.变量
    使用Bash编写Linux Shell脚本8.调试和版本控制
    Perl之单引号\双引号的字符串直接量
    linux bash shell 中的单引号和双引号
    使用Bash编写Linux Shell脚本6.表达式
    Vim的行号、语法显示等设置,即.vimrc文件的配置
  • 原文地址:https://www.cnblogs.com/shenlaiyaoshi/p/7776784.html
Copyright © 2011-2022 走看看