Select in NSArray from generated from JSON - objective-c
I have an NSArray created from a JSON file.
If I just Print the Array to the console I get the following output:
Click me.
First part of file:
{
result = {
"attribute_controlled_attached_particles" = (
{
"attach_to_rootbone" = 0;
id = 1;
name = "Partikel 1";
system = "burningplayer_red";
},
{
"attach_to_rootbone" = 0;
id = 2;
name = "Fliegende Teile";
system = "burningplayer_flyingbits";
},
{
"attach_to_rootbone" = 0;
attachment = muzzle1;
id = 3;
name = "Nemesis-Explosion";
system = "particle_nemesis_burst_blue";
},
{
"attach_to_rootbone" = 0;
id = 4;
name = "Community-Glitzer";
system = "community_sparkle";
},
{
"attach_to_rootbone" = 0;
attachment = halopoint1;
id = 5;
name = Heiligenschein;
system = halopoint;
},
{
"attach_to_rootbone" = 0;
id = 6;
name = "Gr\U00fcnes Konfetti";
system = "superrare_confetti_green";
},
{
"attach_to_rootbone" = 0;
id = 7;
name = "Lila Konfetti";
system = "superrare_confetti_purple";
},
{
"attach_to_rootbone" = 1;
attachment = muzzle;
id = 8;
name = "Spukende Geister";
system = "superrare_ghosts";
},
{
"attach_to_rootbone" = 1;
id = 9;
name = "Gr\U00fcne Energieladung";
system = "superrare_greenenergy";
},
{
"attach_to_rootbone" = 1;
id = 10;
name = "Lila Energieladung";
system = "superrare_purpleenergy";
},
{
"attach_to_rootbone" = 1;
attachment = muzzle;
id = 11;
name = "Kreisendes TF-Logo";
system = "superrare_circling_tf";
},
{
"attach_to_rootbone" = 1;
id = 12;
name = Fliegenschwarm;
system = "superrare_flies";
},
{
"attach_to_rootbone" = 1;
attachment = muzzle;
id = 13;
name = "Brennende Flammen";
system = "superrare_burning1";
},
{
"attach_to_rootbone" = 1;
attachment = unusual;
id = 14;
name = "Sengende Flammen";
system = "superrare_burning2";
},
{
"attach_to_rootbone" = 1;
attachment = muzzle;
id = 15;
name = "Gl\U00fchendes Plasma";
system = "superrare_plasma1";
},
{
"attach_to_rootbone" = 1;
attachment = muzzle;
id = 16;
name = "Lebendiges Plasma";
system = "superrare_plasma2";
},
{
"attach_to_rootbone" = 1;
id = 17;
name = Sonnenstrahlen;
system = "superrare_beams1";
},
{
"attach_to_rootbone" = 1;
attachment = muzzle;
id = 18;
name = "Kreisendes Friedenszeichen";
system = "superrare_circling_peacesign";
},
{
"attach_to_rootbone" = 1;
attachment = muzzle;
id = 19;
name = "Kreisendes Herz";
system = "superrare_circling_heart";
},
{
"attach_to_rootbone" = 1;
id = 20;
name = "Karten-Briefmarken";
system = "stamp_spin";
},
{
"attach_to_rootbone" = 0;
attachment = "cig_drg_smoke";
id = 28;
name = "Eleganter Rauch";
system = "drg_pipe_smoke";
},
{
"attach_to_rootbone" = 1;
id = 29;
name = "St\U00fcrmischer Sturm";
system = "unusual_storm";
},
{
"attach_to_rootbone" = 1;
id = 30;
name = "Eisiger Sturm";
system = "unusual_blizzard";
},
{
"attach_to_rootbone" = 1;
id = 31;
name = "Muttern & Bolzen";
system = "unusual_orbit_nutsnbolts";
},
{
"attach_to_rootbone" = 1;
id = 32;
name = "Kreisende Planeten";
system = "unusual_orbit_planets";
},
{
"attach_to_rootbone" = 1;
id = 33;
name = "Kreisendes Feuer";
system = "unusual_orbit_fire";
},
{
"attach_to_rootbone" = 1;
id = 34;
name = Blubbern;
system = "unusual_bubbles";
},
{
"attach_to_rootbone" = 1;
id = 35;
name = Rauchen;
system = "unusual_smoking";
},
{
"attach_to_rootbone" = 1;
id = 36;
name = Dampfen;
system = "unusual_steaming";
},
{
"attach_to_rootbone" = 1;
id = 37;
name = "Brennende Laterne";
system = "unusual_orbit_jack_flaming";
},
{
"attach_to_rootbone" = 1;
id = 38;
name = "Bew\U00f6lkter Mond";
system = "unusual_fullmoon_cloudy";
},
{
"attach_to_rootbone" = 1;
id = 39;
name = "Blubbernder Kessel";
system = "unusual_bubbles_green";
},
{
"attach_to_rootbone" = 1;
id = 40;
name = "Schauriges, kreisendes Feuer";
system = "unusual_orbit_fire_dark";
},
{
"attach_to_rootbone" = 1;
attachment = muzzle;
id = 43;
name = Messersturm;
system = "unusual_storm_knives";
},
{
"attach_to_rootbone" = 1;
attachment = muzzle;
id = 44;
name = "Nebliger Sch\U00e4del";
system = "unusual_skull_misty";
},
{
"attach_to_rootbone" = 1;
attachment = muzzle;
id = 45;
name = Herbstmond;
system = "unusual_fullmoon_cloudy_green";
},
{
"attach_to_rootbone" = 1;
attachment = muzzle;
id = 46;
name = "Es ist ein Geheimnis f\U00fcr jeden";
system = "unusual_fullmoon_cloudy_secret";
},
{
"attach_to_rootbone" = 1;
attachment = muzzle;
id = 47;
name = "St\U00fcrmische 13. Stunde";
system = "unusual_storm_spooky";
}
);
attributes = (
{
"attribute_class" = "mult_dmg";
defindex = 1;
"description_format" = "value_is_percentage";
"description_string" = "%s1%\U00a0geringerer Schaden";
"effect_type" = negative;
hidden = 0;
"max_value" = "0.85";
"min_value" = "0.95";
name = "damage penalty";
"stored_as_integer" = 0;
},
{
"attribute_class" = "mult_dmg";
defindex = 2;
"description_format" = "value_is_percentage";
"description_string" = "+%s1%\U00a0Schadensbonus";
"effect_type" = positive;
hidden = 0;
"max_value" = "1.1";
"min_value" = "1.05";
name = "damage bonus";
"stored_as_integer" = 0;
},
{
"attribute_class" = "mult_clipsize";
defindex = 3;
"description_format" = "value_is_percentage";
"description_string" = "%s1%\U00a0Magazingr\U00f6\U00dfe";
"effect_type" = negative;
hidden = 0;
"max_value" = "0.75";
"min_value" = "0.9";
name = "clip size penalty";
"stored_as_integer" = 0;
},
{
"attribute_class" = "mult_clipsize";
defindex = 4;
"description_format" = "value_is_percentage";
"description_string" = "+%s1%\U00a0Magazingr\U00f6\U00dfe";
"effect_type" = positive;
hidden = 0;
"max_value" = "1.1";
"min_value" = "1.05";
name = "clip size bonus";
"stored_as_integer" = 0;
},
{
"attribute_class" = "mult_postfiredelay";
defindex = 5;
"description_format" = "value_is_inverted_percentage";
"description_string" = "%s1%\U00a0niedrigere Schussfrequenz";
"effect_type" = negative;
hidden = 0;
"max_value" = "1.25";
"min_value" = "1.05";
name = "fire rate penalty";
"stored_as_integer" = 0;
},
{
"attribute_class" = "mult_postfiredelay";
defindex = 6;
"description_format" = "value_is_inverted_percentage";
"description_string" = "+%s1%\U00a0h\U00f6here Schussfrequenz";
"effect_type" = positive;
hidden = 0;
"max_value" = "0.9";
"min_value" = "0.95";
name = "fire rate bonus";
"stored_as_integer" = 0;
},
{
"attribute_class" = "mult_medigun_healrate";
defindex = 7;
"description_format" = "value_is_percentage";
"description_string" = "%s1%\U00a0Heilungsrate";
"effect_type" = negative;
hidden = 0;
"max_value" = "0.8";
"min_value" = "0.95";
name = "heal rate penalty";
"stored_as_integer" = 0;
},
{
"attribute_class" = "mult_medigun_healrate";
defindex = 8;
"description_format" = "value_is_percentage";
"description_string" = "+%s1%\U00a0Heilungsrate";
"effect_type" = positive;
hidden = 0;
"max_value" = "1.15";
"min_value" = "1.05";
name = "heal rate bonus";
"stored_as_integer" = 0;
},
My Question is: How do I get the name of an item at an index ?
I tried
[[[[news objectAtIndex:0]objectForKey:#"items"]objectAtIndex:2] objectForKey:#"name"];
News is the array that contains the Data !
Hope you can help
Tim
You seem to have a dictionary consisting of several arrays of dictionaries. I think you want something like this... (edit: like mentioned in the comments, it depends which array of dictionaries you need to get the name from, as there seem to be several to chose from in the results).
NSArray *array = [resultDictionary objectForKey:#"attribute_controlled_attached_particles"];
for (NSDictionary *aDictionary in array){
NSString *name = [aDictionary objectForKey:#"name"];
// do what you want with the string...
// could be useful if you for instance need to make an array of all the names
}
Or of course:
NSString *someString = [[array objectAtIndex:3] objectForKey:#"name"];
You have got a dictionary containing another dictionary (not a smart idea), so you should get the dictionary inside it using the objectForKey: selector. Now if you are able to get the key-value of a dictionary, you wouldn't have problems doing it N times.
The [] operator allows you to access the values of an array/dictionary and it works like objectAtIndex:/valueForKey: . Here is how to do it:
NSDictionary* result= json[#"result"];
NSArray* acabArray= result[#"attribute_controlled_attached_particles"];
for(NSDictionary* acabDict in acabArray)
{
NSNumber* num= acabDict[#"attach_to_rootbone"];
NSString* name= acabDict[#"name"];
// Obtain also the other key-values in a similar way
// Do what you want with these values, I suggest to build a custom
// object to hold all these values, and put every object in a mutable array.
}
You have an NSDictionary containing a NSDictionary (keyed by "result") containing an NSArray (keyed by "attribute_controlled_attached_particles"). To get this containg array, you need to do:
NSArray *resultArray = [[jsonDictionary objectForKey:#"result"] objectForKey:#"attribute_controlled_attached_particles"];
Inside the resultArray, you have an ordered list of dictionaries representing news items. So, to get the "name" string for the first index, do
NSDictionary *itemDictionary = [resultArray objectAtIndex:0];
NSString *name = [itemDictionary objectForKey:#"name"];
To enumerate all items, you need to iterate through the resultArray.
Related
Create Order in prestashop programmatically
I am trying to create an order in prestashop programmatically, Here are the steps I am following: $billingAddress = $order->getBillingAddress(); $shippingAddress = $order->getShippingAddress(); if (empty($billingAddress)) { continue; } $id_customer = $this->createPrestashopCustomer($billingAddress, $order->getEmail()); $lines = $order->getLines(); $AddressObject = new AddressCore(); $AddressObject->id_customer = $id_customer; $AddressObject->firstname = $billingAddress->getfirstName(); $AddressObject->lastname = $billingAddress->getlastName(); $AddressObject->address1 = " " . $billingAddress->getHouseNr(); $AddressObject->address1.= " " . $billingAddress->getHouseNrAddition(); $AddressObject->address1.= " " . $billingAddress->getStreetName(); $AddressObject->address1.= " " . $billingAddress->getZipCode(); $AddressObject->address1.= " " . $billingAddress->getCity(); $AddressObject->city = $billingAddress->getCity(); $AddressObject->id_customer = $id_customer; $AddressObject->id_country = CountryCore::getByIso($billingAddress->getCountryIso()); $AddressObject->alias = ($billingAddress->getcompanyName() != "") ? "Company" : "Home"; $AddressObject->add(); $currency_object = new CurrencyCore(); $default_currency_object = $currency_object->getDefaultCurrency(); $id_currency = $default_currency_object->id; $id_address = $AddressObject->id; $cart = new Cart(); $cart->id_customer = (int) $id_customer; $cart->id_address_delivery = $id_address; $cart->id_address_invoice = $id_address; $cart->id_lang = 1; $cart->id_currency = (int) $id_address; $cart->id_carrier = 1; $cart->recyclable = 0; $cart->gift = 0; $cart->add(); if (!empty($lines)) { foreach ($lines as $item) { $cart->updateQty(1, 5, 19); } } $cart->update(); $order_object = new OrderCore(); $order_object->id_address_delivery = $id_address; $order_object->id_address_invoice = $id_address; $order_object->id_cart = $cart->id; $order_object->id_currency = $id_currency; $order_object->id_customer = $id_customer; $CarrierObject = new CarrierCore(); $CarrierObject->delay[1] = "2-4"; $CarrierObject->active = 1; $CarrierObject->name = "ChannelEngine Order2"; $CarrierObject->add(); $id_carrier = $CarrierObject->id; $order_object->id_carrier = $id_carrier; $order_object->payment = "Channel Engine Order"; $order_object->module = "1"; echo $order->getTotalInclVat(); $order_object->valid = 1; $order_object->total_paid_tax_excl = $order->getTotalInclVat(); $order_object->total_discounts_tax_incl = $order->getTotalInclVat(); $order_object->total_paid = $order->getTotalInclVat(); $order_object->total_paid_real = $order->getTotalInclVat(); $order_object->total_products = $order->getSubTotalInclVat() - $order->getSubTotalVat(); $order_object->total_products_wt = $order->getSubTotalInclVat(); $order_object->conversion_rate = 1; $order_object->id_shop = 1; $order_object->id_lang = 1; $order_object->secure_key = md5(uniqid(rand(), true)); $order_id = $order_object->add(); The Order is getting added to admin But somehow I can not see products in the order, Can anyone check and let me know what I am doing wrong here. Also order total is also 0.
You should also create OrderDetail Objects for each product of this order. Have a look at validateOrder() method of PaymentModule Class. Here is an extract from this method: $order = new Order(); $order->product_list = $package['product_list']; if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') { $address = new Address((int)$id_address); $this->context->country = new Country((int)$address->id_country, (int)$this->context->cart->id_lang); if (!$this->context->country->active) { throw new PrestaShopException('The delivery address country is not active.'); } } $carrier = null; if (!$this->context->cart->isVirtualCart() && isset($package['id_carrier'])) { $carrier = new Carrier((int)$package['id_carrier'], (int)$this->context->cart->id_lang); $order->id_carrier = (int)$carrier->id; $id_carrier = (int)$carrier->id; } else { $order->id_carrier = 0; $id_carrier = 0; } $order->id_customer = (int)$this->context->cart->id_customer; $order->id_address_invoice = (int)$this->context->cart->id_address_invoice; $order->id_address_delivery = (int)$id_address; $order->id_currency = $this->context->currency->id; $order->id_lang = (int)$this->context->cart->id_lang; $order->id_cart = (int)$this->context->cart->id; $order->reference = $reference; $order->id_shop = (int)$this->context->shop->id; $order->id_shop_group = (int)$this->context->shop->id_shop_group; $order->secure_key = ($secure_key ? pSQL($secure_key) : pSQL($this->context->customer->secure_key)); $order->payment = $payment_method; if (isset($this->name)) { $order->module = $this->name; } $order->recyclable = $this->context->cart->recyclable; $order->gift = (int)$this->context->cart->gift; $order->gift_message = $this->context->cart->gift_message; $order->mobile_theme = $this->context->cart->mobile_theme; $order->conversion_rate = $this->context->currency->conversion_rate; $amount_paid = !$dont_touch_amount ? Tools::ps_round((float)$amount_paid, 2) : $amount_paid; $order->total_paid_real = 0; $order->total_products = (float)$this->context->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS, $order->product_list, $id_carrier); $order->total_products_wt = (float)$this->context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS, $order->product_list, $id_carrier); $order->total_discounts_tax_excl = (float)abs($this->context->cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS, $order->product_list, $id_carrier)); $order->total_discounts_tax_incl = (float)abs($this->context->cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS, $order->product_list, $id_carrier)); $order->total_discounts = $order->total_discounts_tax_incl; $order->total_shipping_tax_excl = (float)$this->context->cart->getPackageShippingCost((int)$id_carrier, false, null, $order->product_list); $order->total_shipping_tax_incl = (float)$this->context->cart->getPackageShippingCost((int)$id_carrier, true, null, $order->product_list); $order->total_shipping = $order->total_shipping_tax_incl; if (!is_null($carrier) && Validate::isLoadedObject($carrier)) { $order->carrier_tax_rate = $carrier->getTaxesRate(new Address((int)$this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); } $order->total_wrapping_tax_excl = (float)abs($this->context->cart->getOrderTotal(false, Cart::ONLY_WRAPPING, $order->product_list, $id_carrier)); $order->total_wrapping_tax_incl = (float)abs($this->context->cart->getOrderTotal(true, Cart::ONLY_WRAPPING, $order->product_list, $id_carrier)); $order->total_wrapping = $order->total_wrapping_tax_incl; $order->total_paid_tax_excl = (float)Tools::ps_round((float)$this->context->cart->getOrderTotal(false, Cart::BOTH, $order->product_list, $id_carrier), _PS_PRICE_COMPUTE_PRECISION_); $order->total_paid_tax_incl = (float)Tools::ps_round((float)$this->context->cart->getOrderTotal(true, Cart::BOTH, $order->product_list, $id_carrier), _PS_PRICE_COMPUTE_PRECISION_); $order->total_paid = $order->total_paid_tax_incl; $order->round_mode = Configuration::get('PS_PRICE_ROUND_MODE'); $order->round_type = Configuration::get('PS_ROUND_TYPE'); $order->invoice_date = '0000-00-00 00:00:00'; $order->delivery_date = '0000-00-00 00:00:00'; if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Order is about to be added', 1, null, 'Cart', (int)$id_cart, true); } // Creating order $result = $order->add(); if (!$result) { PrestaShopLogger::addLog('PaymentModule::validateOrder - Order cannot be created', 3, null, 'Cart', (int)$id_cart, true); throw new PrestaShopException('Can\'t save Order'); } // Amount paid by customer is not the right one -> Status = payment error // We don't use the following condition to avoid the float precision issues : http://www.php.net/manual/en/language.types.float.php // if ($order->total_paid != $order->total_paid_real) // We use number_format in order to compare two string if ($order_status->logable && number_format($cart_total_paid, _PS_PRICE_COMPUTE_PRECISION_) != number_format($amount_paid, _PS_PRICE_COMPUTE_PRECISION_)) { $id_order_state = Configuration::get('PS_OS_ERROR'); } $order_list[] = $order; if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - OrderDetail is about to be added', 1, null, 'Cart', (int)$id_cart, true); } // Insert new Order detail list using cart for the current order $order_detail = new OrderDetail(null, null, $this->context); $order_detail->createList($order, $this->context->cart, $id_order_state, $order->product_list, 0, true, $package_list[$id_address][$id_package]['id_warehouse']); $order_detail_list[] = $order_detail; if (self::DEBUG_MODE) { PrestaShopLogger::addLog('PaymentModule::validateOrder - OrderCarrier is about to be added', 1, null, 'Cart', (int)$id_cart, true); } // Adding an entry in order_carrier table if (!is_null($carrier)) { $order_carrier = new OrderCarrier(); $order_carrier->id_order = (int)$order->id; $order_carrier->id_carrier = (int)$id_carrier; $order_carrier->weight = (float)$order->getTotalWeight(); $order_carrier->shipping_cost_tax_excl = (float)$order->total_shipping_tax_excl; $order_carrier->shipping_cost_tax_incl = (float)$order->total_shipping_tax_incl; $order_carrier->add(); }
Create Order Programatically in prestashop, we need to use validate order function to create order manually in prestashop. <?php $cart = new Cart(Context::getContext()->cart); $summary = $cart->getSummaryDetails($id_lang,true); $total = (string) $summary['total_price']; $cashondelivery = new CashOnDelivery(); if($cashondelivery->validateOrder((int) $cart->id,2, $total, $cashondelivery->displayName, null, array(),$id_currency, false, false)) { $result['orderid']=(string)$cashondelivery->currentOrder; return $result; }
how can i parse and foreach json tree on objective c
2015-10-13 16:42:55.391 JsonProject[30384:1471391] requestReply: ( { DNumb = 512421421; DTempData = ""; DUUID = 12; Id = 1; }, { DTempData = ""; Id = 2; }, { DTempData = ""; Id = 3; }, { DTempData = ""; Id = 4; }, { DTempData = ""; Id = 5; }, { DTempData = ""; Id = 6; }, { DTempData = ""; Id = 7; }, { DNumb = String; DTempData = ""; DUUID = String; Id = 8; }, { DNumb = 1234; DTempData = ""; DUUID = 4567; Id = 9; }, { DTempData = ""; Id = 10; }, { DTempData = ""; Id = 11; }, { DTempData = ""; Id = 12; }, { DNumb = Message; DTempData = ""; DUUID = isNotReal; Id = 13; } ) This is json data after post method, NSDictionary* responseA = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; NSLog(#"requestReply: %#", responseA[#"GetVerifiedDevices"]); how can i reach members? also check is available any number or character? i was working on C# and i do use foreach, is there parse this data? Thanks
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]
My XML response: { "S:Envelope" = { "S:Body" = { "ns2:getMatchListResponse" = { item = ( { answerTime = { text = 30; }; challengerAppealsGranted = { text = "0 of 16"; }; challengerHandle = { text = manish; }; challengerMatchesPlayed = { text = 93; }; challengerPic = { text = "image.png"; }; challengerScore = { text = 0; }; challengerlosses = { text = 0; }; challengerwins = { text = 4; }; handle1 = { text = sahni; }; handle1AppealsGranted = { text = 5; }; handle1MatchesPlayed = { text = 84; }; handle1Response = { text = Pending; }; handle1Score = { text = 0; }; handle1losses = { text = 0; }; handle1wins = { text = 1; }; handle2MatchesPlayed = { text = 0; }; handle2Score = { text = 0; }; handle2losses = { text = 0; }; handle2wins = { text = 0; }; handle3MatchesPlayed = { text = 0; }; handle3Score = { text = 0; }; handle3losses = { text = 0; }; handle3wins = { text = 0; }; idMatch = { text = 750; }; isAppeal = { text = false; }; isFreeForm = { text = false; }; isMultichoiceQuestion = { text = false; }; isPublic = { text = false; }; matchName = { text = ewtwert; }; matchStartThresholdTime = { text = "4 days 7 hrs"; }; matchStatus = { text = wait; }; matchType = { text = Private; }; noOfPlayers = { text = 2; }; priorityInList = { text = 0; }; scoreToWin = { text = 5; }; timeDuration = { text = "5 days"; }; turnChangesIn = { text = 0; }; }, { answerTime = { text = 30; }; challengerAppealsGranted = { text = "0 of 16"; }; challengerHandle = { text = manish; }; challengerMatchesPlayed = { text = 93; }; challengerPic = { text = "image.png"; }; challengerScore = { text = 0; }; challengerlosses = { text = 0; }; challengerwins = { text = 4; }; handle1MatchesPlayed = { text = 0; }; handle1Score = { text = 0; }; handle1losses = { text = 0; }; handle1wins = { text = 0; }; handle2MatchesPlayed = { text = 0; }; handle2Score = { text = 0; }; handle2losses = { text = 0; }; handle2wins = { text = 0; }; handle3MatchesPlayed = { text = 0; }; handle3Score = { text = 0; }; handle3losses = { text = 0; }; handle3wins = { text = 0; }; idMatch = { text = 749; }; isAppeal = { text = false; }; isFreeForm = { text = false; }; isMultichoiceQuestion = { text = false; }; isPublic = { text = false; }; matchName = { text = gfhf; }; matchStartThresholdTime = { text = "4 days 6 hrs"; }; matchStatus = { text = wait; }; matchType = { text = Public; }; noOfPlayers = { text = 2; }; priorityInList = { text = 0; }; scoreToWin = { text = 5; }; timeDuration = { text = "5 days"; }; turnChangesIn = { text = 0; }; } ); "xmlns:ns2" = "http://services.tgs.com/"; }; }; "xmlns:S" = "http://schemas.xmlsoap.org/soap/envelope/"; }; } I need value of key "matchStartThresholdTime". I do: NSDictionary *dictResult = [XMLReader dictionaryForXMLString:responseString error:nil]; NSDictionary *Enveloper = [dictResult objectForKey:#"S:Envelope"]; NSDictionary *Body = [Enveloper objectForKey:#"S:Body"]; NSDictionary *profileDetails = [Body objectForKey:#"ns2:getMatchListResponse"]; NSMutableArray *items = [profileDetails objectForKey:#"item"]; // NSLog(#"items===>%#",items); NSDictionary *temp1; for(temp1 in items) { thresholdTime = [NSString stringWithFormat:#"%#",[[temp1 objectForKey:#"matchStartThresholdTime"]objectForKey:#"text"]];...thresholdTime is NSString object.......and this line causes exception //NSLog(#"time is===>%#",[[temp1 objectForKey:#"matchStartThresholdTime"]objectForKey:#"text"]); } What is the problem here?
Temp1 contains an NSString Object and not the NSDictionary, that you expect. When dealing with JSON it is wise always to (double) check if a received object is really of the type that you expect. Always use if ([temp1 isKindOfClass:[NSDictionary class]]) ... or so.
how to get pi_image from array in table view
( { property = { "p_address" = sdfsdf; "p_asking_price" = "50000.00"; "p_category_type" = 1; "p_created" = "0000-00-00 00:00:00"; "p_description" = sdfsdf; "p_id" = 2; "p_is_new_property" = 1; "p_modified" = "2013-04-08 15:40:25"; "p_no_of_bedroom" = 1; "p_no_of_otherroom" = 1; "p_no_of_wc" = 2; "p_title" = sadf; "p_type" = demo; }; "property_images" = ( ); "property_local_information" = ( { "li_label" = "Nearby Transport"; "li_order" = 1; "pli_distance" = ""; "pli_logo" = ""; "pli_title" = ""; } ); "property_sale_history" = ( { "psh_history" = sdsdfsd; }, { "psh_history" = sdfdfds; } ); "property_videos" = ( ); }, { property = { "p_address" = dfgsdfg; "p_asking_price" = "44222.00"; "p_category_type" = ""; "p_created" = "0000-00-00 00:00:00"; "p_description" = "Updated by a staff meber (demo2#gmail.com)"; "p_id" = 3; "p_is_new_property" = 1; "p_modified" = "2013-04-09 03:05:09"; "p_no_of_bedroom" = 0; "p_no_of_otherroom" = 0; "p_no_of_wc" = 0; "p_title" = "Test Update"; "p_type" = sdfgsdfgsdg; }; "property_images" = ( { "pi_image" = "prop_img_1594785781_3.png"; } ); "property_local_information" = ( { "li_label" = "Nearby College"; "li_order" = 4; "pli_distance" = utyutyu; "pli_logo" = ""; "pli_title" = tyutyu; } ); "property_sale_history" = ( { "psh_history" = testing; }, { "psh_history" = tyutyutut; } ); "property_videos" = ( { "pv_video" = "prop_vid_730342365_3.flv"; } ); },
Try this if your using json concept NSString *urlString = [NSString stringWithFormat:"your url link"]; NSURL *url = [NSURL URLWithString:urlString]; NSData *data = [NSData dataWithContentsOfURL:url]; NSError *error; NSMutableArray *json = (NSMutableArray*)[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; NSMutableArray *piimage=[json valueForKey:#"pi_image"]; NSLog(#"%#",piimage);
extracting information from NSDictionary
I have a NSDictionary response from a Flickr api request and it's description looks like this: self.userInfo: { "_text" = "\n\n"; person = { "_text" = "\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n"; description = { }; iconfarm = 0; iconserver = 0; id = "83943196#N02"; ispro = 0; location = { }; "mbox_sha1sum" = { "_text" = 7b61c5d24f12345678be82c31234567830540; }; mobileurl = { "_text" = "http://m.flickr.com/photostream.gne?id=12345678"; }; nsid = "12345678#N02"; "path_alias" = ""; photos = { "_text" = "\n\t\t\n\t\t\n\t\t\n\t\t\n\t"; count = { "_text" = 2; }; firstdate = { "_text" = 12345678; }; firstdatetaken = { "_text" = "2012-08-01 12:46:38"; }; views = { "_text" = 0; }; }; photosurl = { "_text" = "http://www.flickr.com/photos/12345678#N02/"; }; profileurl = { "_text" = "http://www.flickr.com/people/12345678#N02/"; }; realname = { "_text" = "Me TheUser"; }; timezone = { label = "Pacific Time (US & Canada); Tijuana"; offset = "-08:00"; }; username = { "_text" = metheuser; }; }; stat = ok; } I'm having truoble figuring out how to extract the realname value into a NSString. I've tried: NSString * temp = [self.userInfo valueForKey:#"realname"]; NSLog (#"FL: nameOfSignedInUser. nameself.userInfo: %#", temp.debugDescription); but that comes back as nil. thank you!
NSString *name = [self.userInfo valueForKeyPath:#"person.realname._text"];
NSString *realName = [[[self.userInfo objectForKey:#"person"] objectForKey:#"realname"] objectForKey:#"_text"];