使用NSmutableDictionary

时间:2014-03-18 12:04:56

标签: ios nsdictionary

我试图做这样的事情......我有一个包含一些数据的数组。即将检查有关该数组中的数据的一些条件,之后,我想通过使用我的数组对象创建一个列表。我在我的Android应用程序中使用hashmaps完成了这个。我想在这里做同样的事情......我听说过NSDictionary ..有人可以指导我..

下面是我的android代码..我想在iOS中做同样的事情

public ArrayList<HashMap<String, String>> getDuplicated(String date,String startTime,String endTime){

     ArrayList<HashMap<String, String>> duplicateList = new ArrayList<HashMap<String, String>>();


     JsonParser jp = new JsonParser();

    String caregiverID = MainActivity.confirm.toString();

    JSONObject param = new JSONObject();
    JSONObject job =  new JSONObject();
    try {
        param.put("caregiverPersonId", caregiverID);
        job = jp.getJSONFromUrl(param, url);

        JSONArray array = job.getJSONArray("d");

        if(array.length()>0)
        {
            JSONObject c1 = array.getJSONObject(0);
            JSONObject apoinmentObj1  = c1.getJSONObject(TAG_APOINMENT);
            userId = apoinmentObj1.getString("UserId");
        }


        for (int i=0;i<array.length();i++){

            //JSONObject toProcess = forShortList.getJSONObject(i).getJSONObject("Appointment");
            JSONObject c = array.getJSONObject(i);



            // Storing  JSON item in a Variable

            JSONObject apoinment = c.getJSONObject(TAG_APOINMENT);


            //String fname = c.getJSONObject("PatientProfile").getString(TAG_Fname);
            String appoinmntID = apoinment.getString(TAG_APOINMENTID);

            JSONObject apoinmentObj  = c.getJSONObject(TAG_APOINMENT).getJSONObject("DayTimeSlot");

            String fname = c.getJSONObject("PatientProfile").getString(TAG_Fname);
            String lname = c.getJSONObject("PatientProfile").getString(TAG_Lname);
            String imageUrl = c.getJSONObject("PatientProfile").getString(TAG_url);

            if(!imageUrl.equalsIgnoreCase("null")){

              if(!imageUrl.equalsIgnoreCase("") ) {

                  String newUrl =  imageUrl.substring(3); 
                //  ActualImage = "http://vardle.paragoncmb.com"+newUrl;
                ActualImage = "http://qa.vardle.com/"+newUrl;
              }
              else{
                ActualImage = null;
              }


            }


            else{
              ActualImage = null; 
            }

            String timeOfStart = apoinmentObj.getString(TAG_START);
            SimpleDateFormat df=new SimpleDateFormat("hh:mm aa");
            Date st=df.parse(timeOfStart);
            Date st_fromClick = df.parse(startTime);
            //String x = df.format(dt);




           // Integer st = Integer.valueOf(timeOfStart.substring(0, 2));
           // Integer st_fromClick = Integer.valueOf(startTime.substring(0, 2));
            String timeOfEnd = apoinmentObj.getString(TAG_END);
           // Integer et = Integer.valueOf(timeOfEnd.substring(0, 2));
           // Integer et_fromClick = Integer.valueOf(endTime.substring(0, 2));


            SimpleDateFormat df2=new SimpleDateFormat("hh:mm aa");
            Date et=df.parse(timeOfEnd);
            Date et_fromClick = df.parse(endTime);


            String jsonDate = apoinmentObj.getString(TAG_DATE);
            String ackwardRipOff = jsonDate.replace("/Date(", "").replace(")/", "");
            Long Ldat = Long.valueOf(ackwardRipOff);
            Date theDate = new Date(Ldat);
            String dateOfAppoinmnt = (String) DateFormat.format("MM/dd/yy", theDate);
            //HERE IS THE POINT IM TALKNG ABOUT
            if((st.before(et_fromClick)  && et.after(st_fromClick))  && dateOfAppoinmnt.equalsIgnoreCase(date)){


                HashMap<String, String> mapForShort = new HashMap<String, String>();


                mapForShort.put(TAG_START, timeOfStart);
                mapForShort.put(TAG_END, timeOfEnd);
                mapForShort.put(TAG_DATE, dateOfAppoinmnt);
                mapForShort.put(TAG_UID, userId);
                mapForShort.put(TAG_APOINMENTID, appoinmntID);
                mapForShort.put(TAG_Fname, fname);
                mapForShort.put(TAG_Lname, lname);
                mapForShort.put(TAG_url, ActualImage);
                duplicateList.add(mapForShort);



            }


        }



     } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return duplicateList;

}

2 个答案:

答案 0 :(得分:0)

您可以创建一个新的NSMutableDictionary和NSMutableArray:

NSMutableArray* myList = [NSMutableArray array];

NSMutableDictionary* mydictionary = [NSMutableDictionary dictionary];
dictionary[@"TAG_START"] = timeOfStart;

[myList addObject:dictionary];

答案 1 :(得分:0)

请查看此网站,获取有关各种数据类型的初学者教程,包括NSDictionary:http://rypress.com/tutorials/objective-c/data-types/nsdictionary.html