دعم الموقع

I'm quite new to programming and I've recently started studying how to make IOS applications. I'm currently making a movie app but I'm stuck on parsing some required data. My JSON looks like this:

  {
     "page":1,
     "results":[
        {
          "adult":false,
          "backdrop_path":"/aBkkrhQS4rO3u1OTahywtSXu3It.jpg",
          "id":127585,
          "original_title":"X-Men: Days of Future Past",
          "release_date":"2014-05-23",
          "poster_path":"/qKkFk9HELmABpcPoc1HHZGIxQ5a.jpg",
          "popularity":35.3226069950748,
          "title":"X-Men: Days of Future Past",
          "vote_average":7.9,
          "vote_count":1020
        },
          {
          "adult":false,
          "backdrop_path":"/rjUl3pd1LHVOVfG4IGcyA1cId5l.jpg",
          "id":119450,
          "original_title":"Dawn of the Planet of the Apes",
          "release_date":"2014-07-11",
          "poster_path":"/aJemoN7F9GrAYjIL94KXww3QWP9.jpg",
          "popularity":10.3351654326512,
          "title":"Dawn of the Planet of the Apes",
          "vote_average":7.9,
          "vote_count":557
        }
    ],
  "total_pages":9412,
  "total_results":188230
  }      

When i try to parse the data, i get the following error:

  Terminating app due to uncaught exception 'NSInvalidArgumentException', 
  reason: '-[__NSCFString countByEnumeratingWithState:objects:count:]: 
  unrecognized selector sent to instance 0x9081000'

My parser looks like this:

  -(void) parseJSONData:(id) JSON
  {
      //Loop through all objects in JSON array
      for (NSDictionary* dict in JSON) {

          //Create a movie object where the json data can be stored
          Movies *movie = [[Movies alloc] init];

          //Get the JSON data from the dictionary and store it at the Movies object
          movie.titel = [dict objectForKey:@"title"];
          movie.image = [dict objectForKey:@"poster_path"];
          movie.votecount = [dict objectForKey:@"vote_count"];
          movie.voteaverage = [dict objectForKey:@"vote_average"];
          movie.movieid = [dict objectForKey:@"id"];
          movie.releasedate = [dict objectForKey:@"release_date"];

          //Add the movies to the array
          [self.movies addObject:movie];
      }
  }

I believe my parser expects only 1 dictionary, while the JSON that I receive is a dictionary within an array. I've searched far and wide and although I have found solutions to problems similar to mine, my knowledge is too small to tweak and apply them to my situation. I was hoping someone here might be able to help me out.

2 ردود (على هذه الصفحة 1 من 1)

Jump to last post

I don't have the specific answer for you but have you looked through what some of the iOS libraries are doing? It might point you in the right direction.

That error means you are trying to parse an object that ain't a string.. I don't know the types of the properties of the Movie Object but they are not all strings. vote_average for example will give you back a CGFloat and vote_count will give you back an NSInteger.

The date also you will need to use a NSDateFormatter for that.

لم تجد الفلم أو المسلسل ؟ سجل دخولك و انشئها

عام

s ركز شريط البحث
p افتح قائمة الملف الشخصي
esc اغلق النافذة المفتوحة
? افتح نافذة اختصارات لوحة المفاتيح

على كافة صفحات الوسائط

b ارجع للخلف (او للصفحة الام عند التطبيق)
e انتقل لصفحة التعديل

على كافة صفحات موسم المسلسل

(السهم الايمن) انتقل للموسم التالي
(السهم الايسر) انتقل للموسم السابق

على كافة صفحات حلقة المسلسل

(السهم الايمن) انتقل للحلقة التالية
(السهم الايسر) انتقل للحلقة السابقة

على كافة صفحات الصور

a افتح صفحة اضافة الصورة

على كافة صفحات التعديل

t افتح محدد الترجمة
ctrl+ s ارسال النموذج

على صفحات المناقشة

n انشى نقاش جديد
w تبديل حالة المتابعة
p تبديل عام / خاص
c تبديل اغلاق / فتح
a افتح الانشطة
r رد على النقاش
l انتقل لأخر رد
ctrl+ enter أرسل رسالتك
(السهم الايمن) الصفحة التالية
(السهم الايسر) الصفحة السابقة

الاعدادات

هل تريد تقييم او اضافة هذا العنصر للقائمة؟

تسجيل الدخول