1

I get a returnString from a WebService in iOS:

[
{"datum":"2013-07-24
09:38:43","nummer":"1017348010239480212208","anmerkung":"Elektronische
Auftragsdaten wurden vom Versender
\u00fcbermittelt"},{"datum":"2013-07-24
09:38:44","nummer":"1017348010239480212208","anmerkung":"Sendung in
Verteilung"},{"datum":"2013-07-24
09:38:44","nummer":"1017348010239480212208","anmerkung":"Sendung in
Verteilung"},{"datum":"2013-07-24
09:38:44","nummer":"1017348010239480212208","anmerkung":"Sendung in
Zustellung"},{"datum":"2013-07-24
09:26:06","nummer":"1017348010239480212208","anmerkung":"Empf\u00e4nger
nicht angetroffen - benachrichtigt"},{"datum":"2013-07-19
06:24:42","nummer":"1017348010239480212208","anmerkung":"Sendung in
Post-Empfangsbox eingelangt"}
]   

the Objective C Code works fine:

#import "SBJson.h"

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
self.textfeld.text = [NSString stringWithFormat: @"%@", returnString];

I try to format the Response with NSMutableArray or NSArray and JSONValue but without success :

NSMutableArray *meinErgebnis = [responseString JSONValue];

NSLog(@"%@",[[meinErgebnis objectAtIndex:0] objectAtIndex:1]);

How to format the returnCode like that?

Nummer: 1017348010239480212208
Anmerkung: Sendung in Verteilung

Nummer: 1017348010239480212208
Anmerkung: Sendung in Post-Empfangsbox

2 Answers 2

2

You can obtain Data with following method,

 id Data = [NSJSONSerialization JSONObjectWithData:fetchedData options:kNilOptions   error:&error];

Then you can loop the data accordingly. For your example,

for(id object in Data)
{
   NSLog(@"%@",[object valueForKey:@"nummer"]);
   NSLog(@"%@",[object valueForKey:@"anmerkung"]);
}

The loop used above is of fast Enumeration type. Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

0

Use following code for get all the values of nummer and anmerkung from your mutable array.

NSMutableArray *meinErgebnis = [responseString JSONValue];

for(int i = 0; i < meinErgebnis.count; i++)
{
    NSLog(@"%@",[[meinErgebnis objectAtIndex:i] objectForKey:@"nummer"]);
    NSLog(@"%@",[[meinErgebnis objectAtIndex:i] objectForKey:@"anmerkung"]);
}

4 Comments

@ArunThiru : fast-enumeration? how?
@LithuT.V For each loop is nothing but fast-enumeration
Can you elaborate? I dont get what you are trying to say
@LithuT.V refer vish answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.