objective-c - json数据处理
巴扎黑
巴扎黑 2017-05-02 09:24:33
0
4
438

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

巴扎黑
巴扎黑

reply all(4)
伊谢尔伦

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 发出去就可以了
黄舟

Send data via ajax request

漂亮男人
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")
            }
        });
黄舟

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?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template