开发者

iPhone- Send JSON Object to PHP server in POST

开发者 https://www.devze.com 2023-02-23 01:22 出处:网络
I would like to send my contact list with all numbers for each numbers. I\'m tr开发者_JAVA百科ying to send a JSON Object (with all my data) to a PHP file and to decode with the json_decode function.

I would like to send my contact list with all numbers for each numbers.

I'm tr开发者_JAVA百科ying to send a JSON Object (with all my data) to a PHP file and to decode with the json_decode function.

Is it possible to use JSON to send to a server by POST in HTTPrequest


Is it possible to use JSON to send to a server by POST in HTTPrequest

JSON is just text. You can send text via POST, right? Then you can send JSON.


You can use JSON.stringify to create a String from a JavaScript Object.

E.g. JSON.stringify({field1:"a", field2:"b"})

I would use any library like jQuery to post JSON data to the server.

Does that answer your question?


First of all, as @Charles said, JSON is a string. As long as it's part of a POST which you can retrieve on your server, it should be enough.

ASIHTTPRequest is a great library for handling POST data sent from the iPhone to your server. Here's an example on how to send a POST: http://allseeing-i.com/ASIHTTPRequest/How-to-use#sending_a_form_post_with_ASIFormDataRequest

Here's a question related to encoding a NSString to JSON: Send NSMutableArray as JSON using JSON-Framework

0

精彩评论

暂无评论...
验证码 换一张
取 消