开发者

Parsing json with touch json

I am trying to parse json file using touch json but when i parse it using method below then the nsdictionary only has makes two keys one for route and second one for status now i want to know how i will get toatl time from this json given at location. i don't know how i to get it.

    NSDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];

.

{
"routes" : [
  {
     "bounds" : {
        "northeast" : {
           "lat" : 31.928820,
           "lng" : 74.342510
        },
        "southwest" : {
           "lat" : 31.490460,
           "lng" : 73.106870
        }
     },
     "copyrights" : "Map data ©2011 Google",
     "legs" : [
        {
           "distance" : {
              "text" : "172 km",
              "value" : 172126
           },
           "duration" : {
              "text" : "1 hour 49 mins",
              "value" : 6548
           },
           "end_address" : "Lahore District, Pakistan",
           "end_location" : {
              "lat" : 31.544820,
              "lng" : 74.340350
           },
           "start_address" : "Clock Tower, Milat Rd, Faisalabad, Pakistan",
           "start_location" : {
              "lat" : 31.490460,
              "lng" : 73.106870
           },
           "steps" : [
              {
                 "distance" : {
                    "text" : "9.4 km",
                    "value" : 9384
                 },
                 "duration" : {
                    "text" : "12 mins",
                    "value" : 714
                 },
                 "end_location" : {
                    "lat" : 31.573580,
                    "lng" : 73.117750
                 },
                 "html_instructions" : "Head \u003cb\u003enorth\u003c/b\u003e on \u003cb\u003eMilat Rd\u003c/b\u003e toward \u003cb\u003eRana Road\u003c/b\u003e",
                 "polyline" : {
                    "levels" : "B??????????@??@???@??B",
                    "points" : "kne_E}te}L}dAuH_l@yEglB_NaWwBgC?gCMkO}AuZ}BeV{AeTiB}vBaPuCY{NyFaFm@_ALiAh@eEbEmBfAuBNqBYqD}@"
                 },
                 "start_location" : {
                    "lat" : 31.490460,
                    "lng" : 73.106870
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "81 m",
                    "value" : 81
                 },
                 "duration" : {
                    "text" : "1 min",
                    "value" : 7
                 },
                 "end_location" : {
                    "lat" : 31.57397000000001,
                    "lng" : 73.11839000000001
                 },
                 "html_instructions" : "Take the ramp to \u003cb\u003ePindi Bhattian - Faisalabad Motorway\u003c/b\u003e",
                 "polyline" : {
                    "levels" : "B??B",
                    "points" : "{uu_E}xg}LeA}@I]@c@"
                 },
                 "start_location" : {
                    "lat" : 31.573580,
                    "lng" : 73.117750
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "44.9 km",
                    "value" : 44868
                 },
                 "duration" : {
                    "text" : "23 mins",
                    "value" : 1357
                 },
                 "end_location" : {
                    "lat" : 31.92320,
                    "lng" : 73.33070000000001
                 },
                 "html_instructions" : "Keep \u003cb\u003eright\u003c/b\u003e at the fork and merge onto \u003cb\u003ePindi Bhattian - Faisalabad Motorway\u003c/b\u003e",
                 "polyline" : {
                    "levels" : "B?@???@???@????@??@???A????@????@??@?????????@??@???@?????@?????@????B",
                    "points" : "ixu_E}|g}L|EoGPm@LmAEo@Mq@a@y@kEcHwk@{x@qQaUcLoMmMiNsX}Wok@ug@_d@ia@yKyKg}DybEerCmyCkKqKkLgKkHuFsI_GsKmGaHmD{KaFcpBg{@gKmE_NaFsFeBiMgDc}Am[qPsDeKkCkU}G_hBem@iYaKczAck@qXkLiw@e^aL}EyYeL_j@_Sqc@qQcr@sZ_HmCuNyEsPcEoQ}CkcHe~@cM}BgGuAuGcByImCqNmFah@cU_f@oSsVqJ_}@g[uKqEkKeFiK_GoH}Eyk@ia@wIqFyLsGuOgHaNcF_f@cOkCs@{AU"
                 },
                 "start_location" : {
                    "lat" : 31.57397000000001,
                    "lng" : 73.11839000000001
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "107 km",
                    "value" : 107137
                 },
                 "duration" : {
                    "text" : "55 mins",
                    "value" : 3298
                 },
                 "end_location" : {
                    "lat" : 31.54130,
                    "lng" : 74.26101000000001
                 },
                 "html_instructions" : "Take the exit onto \u003cb\u003eLahore - Islamabad Motorway/M-2\u003c/b\u003e",
                 "polyline" : {
                    "levels" : "B??@???@???@???@??@?@??@???@????@???@???@?@@???@??A??@??@@??@??????@??@??????@?????@??????@??????@????@????@????@??@?????A???@?@??????@???@@???A???@?@?@??@?????@?????A?????@??@????@??@??????@????A????@????B",
                    "points" : "__zaE{kq~LuKqA}AGmBL_Cj@kBbAy@r@}AtBq@zAu@|CU~DJdCl@jDr@xBpApBr@f@v@`@`AR|BAxBu@~AcBb@_Al@kCzBmP`AgLpAqTf@mOdAwuA^{It@yJbD}[b@sITeKFaMu@wVo@uNGkOxEwgC~@gt@tAijB\\wXlRyjGdAeu@xAoeCIiQeDi~AScRDmUjE}wBx@}S|BsSzEiWd_A{mDhIq]jVgvApG}ZnI}\\lnAmlEbK}[v~@_sCnEmP|DeRhC}Oh^oiClCwUjDkRpBcJ~B}IzGqTrHuRtE{JbFwJpFeJj^oi@jFaJhGwLbF_LrCkHzGaShFyR|C{NhM{s@~DwPvCoKdGsQhGiOdBgBxK{UjGsNbEsK`EkM|DcNpD{PzC}P~Ksu@jGi_@pJce@pFsTjeAobE|Ui|@dk@{lBrJ}\\te@ygBdDeOpBkLlQinAfCwMnE}QfD_LrI{Uz_@a|@vGuO`GuOfF}Oz[_kAnIeXdX_u@dD_KrOsa@bHaQfL_[tGaV|EuTxA}HnDcWbAqJxIslAxFqr@DwCdC{`@nAaW|Bsp@~EsbBhAkS~@oL|@oIpBkOre@oxCbGka@``@{`DvBaNnCyNpDwOxCqKbJsWjE_KrFeLxJcQ`_Bs}BvL}QfW_b@rr@}mAfJyRdHaR~CeKvFeUrDsStByNh@oCx@kDnBkGhCcGfEcHfBaCbDiD|AwAdCiBrD}BrDgBrBu@p_Bwe@jKeCfPmChQcBdOu@`IS~GCnOJtuAnAzF@fIKzW_B`QsBxGcAvJsBtJaCnIeC`GwB`CwAp^cO`PmFlQkE|FgAvg@wHtI_CtDsAxQ_J`vBagAxNgHnYoOvGmEhFoEdHkHx~AevBxEcFrEcD"
                 },
                 "start_location" : {
                    "lat" : 31.92320,
                    "lng" : 73.33070000000001
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "0.4 km",
                    "value" : 407
                 },
                 "duration" : {
                    "text" : "1 min",
                    "value" : 36
                 },
                 "end_location" : {
                    "lat" : 31.538880,
                    "lng" : 74.26387000000001
                 },
                 "html_instructions" : "Take the exit",
                 "polyline" : {
                    "levels" : "B?@??B",
                    "points" : "clo_EibgdMdAeAjJqG`@w@Fa@FiC"
                 },
                 "start_location" : {
                    "lat" : 31.54130,
                    "lng" : 74.26101000000001
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "2.4 km",
                    "value" : 2353
                 },
                 "duration" : {
                    "text" : "4 mins",
                    "value" : 228
                 },
                 "end_location" : {
                    "lat" : 31.532090,
                    "lng" : 74.28720000000001
                 },
                 "html_instructions" : "Continue straight",
                 "polyline" : {
                    "levels" : "B???@?B",
                    "points" : "_}n_EetgdMU_DJiCvB}IjJ{p@fGsVjRas@"
                 },
                 "start_location" : {
                    "lat" : 31.538880,
                    "lng" : 74.26387000000001
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "27 m",
                    "value" : 27
                 },
                 "duration" : {
                    "text" : "1 min",
                    "value" : 3
                 },
                 "end_location" : {
                    "lat" : 31.532120,
                    "lng" : 74.287470
                 },
                 "html_instructions" : "Take the ramp to \u003cb\u003eMultan Road\u003c/b\u003e",
                 "polyline" : {
                    "levels" : "BB",
                    "points" : "qrm_E_fldMEu@"
                 },
                 "start_location" : {
                    "lat" : 31.532090,
                    "lng" : 74.28720000000001
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "0.1 km",
                    "value" : 112
                 },
                 "duration" : {
                    "text" : "1 min",
                    "value" : 8
                 },
                 "end_location" : {
                    "lat" : 31.532940,
                    "lng" : 74.28810
                 },
                 "html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eMultan Road\u003c/b\u003e",
                 "polyline" : {
                    "levels" : "B?B",
                    "points" : "wrm_EugldMyC_BI]"
                 },
                 "start_location" : {
                    "lat" : 31.532120,
                    "lng" : 74.287470
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "2.9 km",
                    "value" : 2854
                 },
                 "duration" : {
                    "text" : "6 mins",
                    "value" : 333
                 },
                 "end_location" : {
                    "lat" : 31.553730,
                    "lng" : 74.304440
                 },
                 "html_instructions" : "\u003cb\u003eMultan Road\u003c/b\u003e turns slightly \u003cb\u003eleft\u003c/b\u003e and becomes \u003cb\u003eMultan Rd\u003c/b\u003e",
                 "polyline" : {
                    "levels" : "B??@???@??@?@??????B",
                    "points" : "{wm_EskldMgP_KyNqKcAi@_PoF_JeBcBu@W?qDcCKWiHoEmMmL_NeKuAaCwEgKaBaFe@w@_@W{@]s@A"
                 },
                 "start_location" : {
                    "lat" : 31.532940,
                    "lng" : 74.28810
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "1.3 km",
                    "value" : 1329
                 },
                 "duration" : {
                    "text" : "3 mins",
                    "value" : 169
                 },
                 "end_location" : {
                    "lat" : 31.548770,
                    "lng" : 74.31503000000001
                 },
                 "html_instructions" : "At the roundabout, take the \u003cb\u003e4th\u003c/b\u003e exit onto \u003cb\u003eBahawalpur Rd\u003c/b\u003e",
                 "polyline" : {
                    "levels" : "B???@????@?????B",
                    "points" : "yyq_EwqodMkAHu@YYe@AeANQz@?zC}ArDeCpAsAnBmF`AeBnAcD~FmTnCmLAk@"
                 },
                 "start_location" : {
                    "lat" : 31.553730,
                开发者_JAVA百科    "lng" : 74.304440
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "63 m",
                    "value" : 63
                 },
                 "duration" : {
                    "text" : "1 min",
                    "value" : 57
                 },
                 "end_location" : {
                    "lat" : 31.54826000000001,
                    "lng" : 74.315230
                 },
                 "html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e onto \u003cb\u003eFerozepur Rd\u003c/b\u003e",
                 "polyline" : {
                    "levels" : "B??B",
                    "points" : "yzp_E}sqdMHQb@?v@U"
                 },
                 "start_location" : {
                    "lat" : 31.548770,
                    "lng" : 74.31503000000001
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "2.4 km",
                    "value" : 2382
                 },
                 "duration" : {
                    "text" : "3 mins",
                    "value" : 171
                 },
                 "end_location" : {
                    "lat" : 31.53877000000001,
                    "lng" : 74.33630000000001
                 },
                 "html_instructions" : "Slight \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eJail Rd\u003c/b\u003e",
                 "polyline" : {
                    "levels" : "B????@??@????B",
                    "points" : "swp_EeuqdMtHmKlHgOj@q@rC{BzB}BVuA~Da{@RsBb@uAXe@hKsJpBeCbDqF"
                 },
                 "start_location" : {
                    "lat" : 31.54826000000001,
                    "lng" : 74.315230
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "0.4 km",
                    "value" : 402
                 },
                 "duration" : {
                    "text" : "1 min",
                    "value" : 60
                 },
                 "end_location" : {
                    "lat" : 31.540140,
                    "lng" : 74.34006000000001
                 },
                 "html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eDanepur Rd\u003c/b\u003e",
                 "polyline" : {
                    "levels" : "B???B",
                    "points" : "i|n_E{xudMe@mI_@eCw@yAsCaE"
                 },
                 "start_location" : {
                    "lat" : 31.53877000000001,
                    "lng" : 74.33630000000001
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "14 m",
                    "value" : 14
                 },
                 "duration" : {
                    "text" : "1 min",
                    "value" : 8
                 },
                 "end_location" : {
                    "lat" : 31.540060,
                    "lng" : 74.339950
                 },
                 "html_instructions" : "Sharp \u003cb\u003eleft\u003c/b\u003e to stay on \u003cb\u003eDanepur Rd\u003c/b\u003e",
                 "polyline" : {
                    "levels" : "BB",
                    "points" : "{do_EkpvdMNT"
                 },
                 "start_location" : {
                    "lat" : 31.540140,
                    "lng" : 74.34006000000001
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "0.3 km",
                    "value" : 307
                 },
                 "duration" : {
                    "text" : "1 min",
                    "value" : 43
                 },
                 "end_location" : {
                    "lat" : 31.541860,
                    "lng" : 74.34239000000001
                 },
                 "html_instructions" : "Sharp \u003cb\u003eright\u003c/b\u003e to stay on \u003cb\u003eDanepur Rd\u003c/b\u003e",
                 "polyline" : {
                    "levels" : "B?B",
                    "points" : "kdo_EuovdMqHoKu@wA"
                 },
                 "start_location" : {
                    "lat" : 31.540060,
                    "lng" : 74.339950
                 },
                 "travel_mode" : "DRIVING"
              },
              {
                 "distance" : {
                    "text" : "0.4 km",
                    "value" : 406
                 },
                 "duration" : {
                    "text" : "1 min",
                    "value" : 56
                 },
                 "end_location" : {
                    "lat" : 31.544820,
                    "lng" : 74.340350
                 },
                 "html_instructions" : "Take the 2nd \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eAikman Rd\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eDestination will be on the right\u003c/div\u003e",
                 "polyline" : {
                    "levels" : "B????B",
                    "points" : "soo_E}~vdMQWUIq@AWJ}MnL"
                 },
                 "start_location" : {
                    "lat" : 31.541860,
                    "lng" : 74.34239000000001
                 },
                 "travel_mode" : "DRIVING"
              }
           ],
           "via_waypoint" : []
        }
     ],
     "overview_polyline" : {
        "levels" : "B@??@?@?A@@@?@?@?@?A@?@@????@??@??@?@?@?@?@?B?@@@?@@@?@?@?@@?@??A?@?@@@??@?@??@??@???@??@??@??@?@@?A?@@??@???A?@@@?@??@?A??@@@?@?@??A?@?@?A??@A@@@@@??A@?@???@@??@@@?B",
        "points" : "kne_E}te}LcpMy`AuCY{NyFaFm@iCv@sHjGuBNcHwAmA_CnF}Hg@iFcr@_bAu^qc@ag@gg@i}AyvAg}DybEq~C_fDwU}Ri_@{TgxCyoA}TmG{zBme@uxCebAczAck@}}Aor@ydAe`@uvAem@uWgJcc@aJkcHe~@iZiGc]iLaoAsi@_cBin@eYoO{|@qm@iWsMgTkI{h@gP_S_CmFx@sElD_ClFm@jGx@pHxDrGvFr@xEyC`EoT~Ccd@lBefB|Gg}@\\gYmByv@xEwgCrDiyDlRyjGdAeu@xAoeCoDspBMqh@jE}wBx@}S|BsSzEiWniAmlEjVgvA`R{x@lnAmlEjqAkaEfIcc@vb@g`D|Kmh@zGqThOq^tM}Uve@qt@`Scc@dO{f@fRwcAvIg]nO}a@dBgBdToe@dK_ZnJ_`@fY{gBbRwz@h|Ay_Gxv@yjCte@ygBvGq\\lQinAvIu`@zN{b@tp@m}Arm@cuBjdAuqCtGaVvHs^rFub@rQe`CzEu}@|IgtChC{`@nD{Yvm@{zD``@{`DxLsn@|Ned@xXij@xlBqpCzjA}pBfJyRdMg^vFeUrI}g@hDwLpIgPnNmNzM{Gp_Bwe@r\\sGpk@mDhaClAzW_BzYwD|`@{Jv{@a]jYsGvg@wHjOsEtxCi{Afb@}UnO{Nx~AevBxEcFdS{Nl@uBEwKbNy{@lZklAig@y\\{^kKgNkJm\\sXuLcX{Au@{C?y@kBpN{I`GwNvKyc@zAUtHmKlHgOzHkHjFkaA|@{BhKsJtGwJwAwNcPaV_B?}MnL"
     },
     "summary" : "Pindi Bhattian - Faisalabad Motorway and Lahore - Islamabad Motorway/M-2",
     "warnings" : [],
     "waypoint_order" : []
  }
],
"status" : "OK"
}


Ok, at the top level dictionary you only have two keys. Your JSON string looks a bit like this:

{ "routes" : [ ... lots of stuff ... ], "status" : "OK" }

So in the dictionary you get back, the object for the "routes" key will be an array presumably of routes. You'll have to traverse the structure to find the elements you are interested in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜