search

Home  >  Q&A  >  body text

objective-c - json数据处理

OC 如何将{"message":{"function":"user_login","user":{"name":"admin","password":"admin"}}}将这个登录请求json通过socket TCP发给服务器

巴扎黑巴扎黑2758 days ago441

reply all(4)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-05-02 09:26:33

    I know the answer. I tried it myself and just wrote it
    `NSDictionary *dict = @{

                        @"message":@{
                        @"function":@"user_login",
                        @"user":@{
                        @"name":_TextField.text,
                        @"password":_PassTextField.text
                                             }}};`
                                             
                                     将字典转成NSData在转成NSSString后面拼接上数据包的结尾,之后在转换成NSData通过tcp 发出去就可以了

    reply
    0
  • 黄舟

    黄舟2017-05-02 09:26:33

    Send data via ajax request

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-02 09:26:33

    var url = "http://www.xxx.com"
    var data = {"message":
        {"function":"user_login",
             "user":{   
                     "name":"admin",
                     "password":"admin"
                     }
        }
    }
    
    $.ajax({
                cache: true,
                type: "POST",
                url: url,
                data: data
                async: false,
                error: function(request) {
                    alert("NO");
                },
                success: function(data) {
                    alert("OK")
                }
            });

    reply
    0
  • 黄舟

    黄舟2017-05-02 09:26:33

    It is not recommended to manually operate the socket to complete things like sending login requests. Why not try a mature network framework such as AFNetworking?

    reply
    0
  • Cancelreply