1

I have JSON like this:

[{
"username":"bitu","password":"123456", "id":"1"
},
{
"username":"admin","password":"admin", "id":"2"
},
{
"username":"demo","password":"demo", "id":"3"
},
{
"username":"admin","password":"admin", "id":"8"
},
{
"username":"admin","password":"admin", "id":"5"
}]

I want to use NSMutableArray for get "id". How I can do it? Help me, please!

2

5 Answers 5

1
NSLog(@"%@",[[yourArray objectAtIndex:index] valueForKey:@"id"]);
Sign up to request clarification or add additional context in comments.

Comments

1

Get Value with objectAtIndex and valueForKey from NSMutableArray

NSString *UserName = [[yourArray objectAtIndex:index] valueForKey:@"username"];//if you required
NSString *Password = [[yourArray objectAtIndex:index] valueForKey:@"password"];//if you required
NSString *UID = [[yourArray objectAtIndex:index] valueForKey:@"id"];

:)

Comments

0

let NSArray *info array contains your data. Here I am going to retrive your data and save it in NSMutableArray name, password and id.

Initailise these arrays at viewDidLoad methods as

   NSMutableArray name=[[NSMutableArray alloc] init]; 
   NSMutableArray password=[[NSMutableArray alloc] init]; 
   NSMutableArray id=[[NSMutableArray alloc] init];

Use following code after retriving JSON response

   NSArray *info;  // this array contains your data
   int counter=[info count];

   for(int i=0;i<counter;i++)
   {
         NSDictionary *currentObject=[info objectAtIndex:i];
         NSString *userName=[currentObject objectForKey:@"username"];
         NSString *userPassword=[currentObject objectForKey:@"password"];
         NSString *userID=[currentObject objectForKey:@"id"];
         [name addObject:userName];
         [password addObject:userPassword];
         [id addObject: userID];
   }

Comments

0
NSMutableArray *idArray = [[NSMutableArray alloc] init];

    for (NSDictionary *obj in yourJsonArray) {
        [idArray addObject:[obj objectForKey:@"id"]];
    }
NSLog(@"%@",idArray);

Comments

0

Example, Array have string objects.

Acccess:
NSString.FromHandle(deviceList.ValueAt(i));

Comments

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.