I am trying to use an API to request grades from our schools grading system in order to create an app that students can use to check their grades. I am using an NSURL request to fetch this data and it comes back in the form of NSMutableData
. When that returned data is printed as a string it looks something like this:
{"ss#":null,"country":"United States","nick_name":null,"teacher_id":null,"parent":false,"teacher":true,"sms_email":null,"first_name":"Will","joined_at":"2015-10-22T16:58:51-07:00","monitor":false,"picture":"http://sbms.neolms.com/files/root/Hikaru.jpg?lmsauth=f66e77cf0971fc70efd01cd63c403e948afba1f4","student_id":null,"zip":null,"city":null,"student":false,"last_name":"Oakley","state":"CA","street_1":null,"skype":null,"assistant":false,"logins":1,"password":"1fc87c4f58bc472cb2ed2173ac048152242b7e49","birthdate":null,"email":null,"street_2":null,"last_login_at":"2015-10-22T16:58:53-07:00","first_login_at":"2015-10-22T16:58:53-07:00","userid":"woakley5","id":3016816,"administrator":true}
[Don't worry none of this data is personal, it is all from a test "school" that I setup in order to make this app]
So you can see that the request returns a huge list of data with properties followed by values. All of these properties (i.e. country
, nick_name
, teacher_id
etc.) are all in there as expected from reading the API docs. My question is how would I filter out that data and create a string from one specific property. For example, I wanted to make a string called firstName
using the first_name
property from this NSMutableData
. How would I pull that specific property out of the data set and assign it to a string? If you have to research this specific API, it is the NEO LMS API found here: neolms.com/info/features.
You can access like this:
Objective-C:
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
NSString *firstName = [dic objectForKey:"first_name"];