-4

In this app someone has built for me has used this code in order to parse a json array:

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/lending.php?category_id=1",host_name ]]];
[request setRequestMethod:@"GET"];

It works fine, now, what I need is instead of the lendig.php I need to insert this array, which is in fact the output of the json array:

[{"name":"Ekspres Kredi","category_id":"1","id":"2"},{"name":"Kredi p\u00ebr Pushime ","category_id":"1","id":"4"},{"name":" Kredi Konsumuese ","category_id":"1","id":"5"},{"name":"Auto Kredi ","category_id":"1","id":"6"}]

How can I insert that instead?

It should be something like:

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"[{"name":"Ekspres Kredi","category_id":"1","id":"2"},{"name":"Kredi p\u00ebr Pushime ","category_id":"1","id":"4"},{"name":" Kredi Konsumuese ","category_id":"1","id":"5"},{"name":"Auto Kredi ","category_id":"1","id":"6"}]",host_name ]]];
[request setRequestMethod:@"GET"];
iDev
  • 23,310
  • 7
  • 60
  • 85
Alb M
  • 151
  • 10
  • 2
    You need to hit google and search [how to send request as post with asihttprequest](https://www.google.com/#hl=en&tbo=d&sclient=psy-ab&q=how+to+send+request+as+post+with+asihttprequest&oq=how+to+send+request+as+post+with+asihttp&gs_l=serp.3.0.33i21.6605.7048.0.8110.4.4.0.0.0.0.118.358.3j1.4.0.les%3B..0.0...1c.1.h1CE2sUh3gc&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&fp=4a19662fa4882be9&biw=1398&bih=783)? You can come to SO with a specific question after that. – iDev Jan 25 '13 at 20:12
  • 2
    And, so far as I can tell, this question has nothing to do with parsing JSON. – Hot Licks Jan 25 '13 at 20:17
  • I googled before.. well sorry, maybe i on't know even what i should do ... so a hint.. – Alb M Jan 25 '13 at 20:19

1 Answers1

0

First of all you should have clear what you want to do. Anyway here I'm suppose that you want to send some data to a server, in this case you use a POST request.

NSString *jsonString = @"{\"name\":\"Ekspres Kredi\",\"category_id\":\"1\",\"id\":\"2\"},{\"name\":\"Kredi p\u00ebr Pushime \",\"category_id\":\"1\",\"id\":\"4\"},{\"name\":\" Kredi Konsumuese \",\"category_id\":\"1\",\"id\":\"5\"},{\"name\":\"Auto Kredi \",\"category_id\":\"1\",\"id\":\"6\"}"


NSURL *url = [NSURL URLWithString:@"http://myserver.com/post.php"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request addRequestHeader:@"Content-Type" value:@"application/json"];
[request appendPostData:[jsonString  dataUsingEncoding:NSUTF8StringEncoding]]; 
[request startAsynchronous];

By setting the body of the request the method used will be POST.

oiledCode
  • 8,589
  • 6
  • 43
  • 59