In My Application i am Using ArcGIS . in that one i want Search one place and get the places related to that name. Now I want to Parse all the address of that places and put them in a table View. after typing the address and after i press search Button i will get all the Markers on the Map. Now i'm trying to get the complete address of the Place But i was unable to do this.I want to get "place_addr" value from the below string can any one please help me how can i get that value in ios
AGSFindLocationResult name=Disneyland, extent=AGSEnvelope: xmin = -13129988.221853, ymin = 4000701.846518, xmax = -13124422.247314, ymax = 4007401.106877, spatial reference: [AGSSpatialReference: wkid = 102100, wkt = null], graphic=geometry: AGSPoint: x = -13127204.667522, y = 4004050.640580, spatial reference: [AGSSpatialReference: wkid = 102100, wkt = null], symbol: { AGSPictureMarkerSymbol: imageName: BluePushpin.png, width: 36.000000, height: 36.000000 }, attributes: {
AddBldg = "";
AddNum = "";
AddNumFrom = "";
AddNumTo = "";
"Addr_type" = POI;
City = Anaheim;
Country = USA;
DisplayX = "-117.923687";
DisplayY = "33.815467";
Distance = 0;
LangCode = "";
"Loc_name" = "Gaz.WorldGazetteer.POI2";
"Match_addr" = Disneyland;
Nbrhd = "";
Phone = "(714)781-4565";
PlaceName = Disneyland;
"Place_addr" = "1313 S Disneyland Dr Anaheim, CA 92802";
Postal = "";
PostalExt = "";
Rank = "2.5";
Region = California;
Score = 100;
Side = "";
StAddr = "";
StDir = "";
StName = "";
StPreDir = "";
StPreType = "";
StType = "";
Subregion = Orange;
Type = "Amusement Park";
URL = "";
X = "-117.923687";
Xmax = "-117.898691";
Xmin = "-117.948691";
Y = "33.815467";
Ymax = "33.84047000000002";
Ymin = "33.79047";
}, visible: 1
IF what you're getting back really is a string, then you should look at the string searching methods like rangeOfString.
That will return an NSRange that contains your label, "place_addr".
Then you'd want to search from that point forward for a semicolon, using the related method rangeOfString:options:range:, that searches in a specific range of a string.
Finally, you'd need to calculate a range for the contents, that would be 5 characters past the end of the NSRange of "place_addr", and up to, but not including, the final semicolon.
Then you'd use substringWithRange to extract the string who's range you calculated above.
Give that a try, and come back if you have trouble.
Please try the code below
- (NSArray *)findKey:(NSString *)key inString:(NSString *)allString
{
NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:1];
NSArray *splitArray = [allString componentsSeparatedByString:#";"];
for (NSString *s in splitArray) {
NSArray * keyValueArry = [s componentsSeparatedByString:#"="];
if([keyValueArry count] > 1)
{
NSString *_key = [keyValueArry objectAtIndex:0];
NSString *_value = [keyValueArry objectAtIndex:1];
if([_key isEqualToString:key])
{
[result addObject:_value];
}
}
}
return result;
}
where key is place_addr, and allString is as your sample string.
Related
I'm struggling with this dataset:
stopsArray: (
(
{
DistanceFromStart = 0;
Ordinal = 1;
Stop = {
Lat = "38.90282440185547";
Lon = "-77.03208160400391";
OrgAbbr = "<null>";
OrgId = DcCi;
StopCode = 1001259;
StopId = "DcCi_1445_7727";
StopName = "NW 14TH ST & NW K ST";
};
},
{
DistanceFromStart = "0.443314063224555";
Ordinal = 2;
Stop = {
Lat = "38.90834426879883";
Lon = "-77.03208923339844";
OrgAbbr = "<null>";
OrgId = DcCi;
StopCode = 1001393;
StopId = "DcCi_1445_7808";
StopName = "NW 14TH ST & NW RHODE ISLAND AV";
};
},
{
DistanceFromStart = "1.050716048463951";
Ordinal = 3;
Stop = {
Lat = "38.91703033447266";
Lon = "-77.03196716308594";
OrgAbbr = "<null>";
OrgId = DcCi;
StopCode = 17348;
StopId = "DcCi_1445_6674";
StopName = "NW 14TH ST & NW U ST";
};
},
I'm not sure if this is an array, a dictionary, or a combination. How do I tell the difference?
How would I pull out the "Ordinal" field, as well as elements in the "Stop" dataset?
To get the stopsArray data, I used this line:
stopsArray = [variantArray valueForKey:#"Stops"];
I've tried to pull the first Ordinal field (i.e. 1) with this:
NSMutableArray *array = stopsArray[0];
NSString *string = [array valueForKey:#"Ordinal"];
NSLog(#"string: %#", string);
But that results in:
string: (
1,
2,
3,
4,
5,
6,
7
)
Any ideas to stop my hair coming out would be most welcome.
I'll keep at it meanwhile.
Firstly, its an array of objects of type dictionary.
Secondly, the data doesn't seem to be properly formatted.
Its like an array with a single object of type dictionary, but that single object contains all the different dictionary values.
hence your result of
string: (
1,
2,
3,
4,
5,
6,
7
)
What seems to me the problem is the second open bracket
stopsArray: (
(
{
Try doing this...
NSMutableArray *array = stopsArray[0];
NSMutableArray *actualDataArray = array[0];
and then
NSString *string = [actualDataArray[INDEX_OF_DIC_OBJECT] valueForKey:#"Ordinal"];
NSLog(#"string: %#", string);
Lemme know if it works.
Updated Solution
What eventually worked for David DelMonte.
NSString *string = [[[stopsArray objectAtIndex:0] objectAtIndex:0] objectForKey:#"Ordinal"];
let jsonResult1:NSDictionary = NSJSONSerialization.JSONObjectWithData(da!, options:NSJSONReadingOptions.MutableContainers , error: &error) as NSDictionary
println(jsonResult1)
getting below data in console
{
0 = {
"consulting_dr" = "DR.Appaji .";
"current_bed_nr" = 0;
"current_room_nr" = 0;
"discharge_date" = "03/03/2015 00:00";
"encounter_date" = "02/03/2015 12:45";
"encounter_nr" = 201503024000;
info = "";
"item_description" = "";
name = "Mrs. mythily S";
pdob = "01/08/1976";
pid = 100004;
psex = f;
pyear = "38 Years";
};
1 = {
dosage = 1;
drdate = "25/08/2014";
drnotes = "";
drugclass = Tablet;
duration = "5 day";
frequency = "";
medicine = "ACECLOFENAC+PARACETAMOL";
route = Oral;
tcomplients = "";
};
2 = {
BMI = "A:1:{s:4:\"SPO2\";s:1:\"1\";}";
BSA = "A:1:{s:4:\"SPO2\";s:1:\"1\";}";
"Dystolic_bp" = 29;
Height = 24;
Pulse = 26;
Respiration = 27;
"Systolic_bp" = 28;
Temp = 25;
Weight = 22;
dosage = 1;
drdate = "25/08/2014";
drnotes = "";
drugclass = Tablet;
duration = "5 day";
frequency = "";
medicine = RABEPRAZOLE;
route = Oral;
tcomplients = "";
};
}
how to store this in array
That is a Dictionary. It is easy to get just the data without the keys.
In Objective-C it would be :
NSArray *allData = [jsonResult1 allValues];
For swift it should be like: (not sure about syntax)
var allData = jsonResult1.allValues()
If you're up for it, you should give SwiftyJSON a try.
https://github.com/SwiftyJSON/SwiftyJSON
I've recently used it for an application that deals with a ton of JSON responses from a web service and SwiftyJSON has made it super easy for me to deal with JSON data in Swift. It will convert NSData to Dictionaries or Arrays seamlessly for you.
My application has an NSDictionary containing many other NSDictionary inside it. If I print out this dictionary it reads as follows:
oxip = {
created = "2014-02-10 14:42:59";
lastMsgId = "";
requestTime = "1.6434";
response = {
code = 001;
debug = "";
message = success;
request = getHierarchyByMarketType;
text = "\n";
williamhill = {
class = {
id = 1;
maxRepDate = "2014-02-10";
maxRepTime = "07:31:48";
name = "UK Football";
text = "\n";
type = (
{
id = 2;
lastUpdateDate = "2013-12-26";
lastUpdateTime = "13:32:54";
market = (
{
betTillDate = "2014-02-15";
betTillTime = "15:00:00";
date = "2014-02-15";
id = 140780553;
lastUpdateDate = "2014-02-10";
lastUpdateTime = "14:09:13";
name = "Queen of the South v Dundee - Match Betting";
participant = (
{
handicap = "";
id = 496658381;
lastUpdateDate = "2014-02-10";
lastUpdateTime = "14:09:13";
name = Dundee;
odds = "11/8";
oddsDecimal = "2.38";
text = "\n\n\n\n\n\n";
},
{
handicap = "";
id = 496658380;
lastUpdateDate = "2014-02-10";
lastUpdateTime = "14:09:13";
name = Draw;
odds = "5/2";
oddsDecimal = "3.50";
text = "\n";
},
{
handicap = "";
id = 496658379;
lastUpdateDate = "2014-02-10";
lastUpdateTime = "14:09:13";
name = "Queen of the South";
odds = "11/8";
oddsDecimal = "2.38";
text = "\n";
}
);
text = "\n";
time = "15:00:00";
}
What is the best possible way for my application to reach the NSDictionary with the name of:
name = "Queen of the South v Dundee - Match Betting"
without the need of going through each individual dictionary and finding its object for key?
You can use valueForKeyPath for that. It accepts a path, separated by dots. Example:
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"https://dl.dropboxusercontent.com/u/1365846/21680479.json"]]
options:0
error:nil];
NSLog(#"%#", [dict valueForKeyPath:#"response.williamhill.class.type.market.name"]);
This depends on the representation of dictionary. If the williamhill part is changing, then it does not work, of course.
There is no way to obtain a reference within a map data type (in this case, an NSDictionary) without traversing it. Think of the simplified version of this problem: You have a linked list with N elements and you wish to reach the N'th element. Because this is a linked list, you'll have to go through all other N-1 nodes in order to obtain the last reference.
An NSDictionary is a hash based data type in which keys and values are stored. In the case you describe, you have no reference to the nested object (an NSDictionary itself) so you must also traverse all of the dictionaries containing it.
Hope this helps point you in the right direction.
<__NSArrayM 0x82701fe0>(
{
Distance = "2.08";
address = Manjalpur;
dob = "09-04-1986 ";
email = "kan#t.com";
facebookid = "";
fname = kanan;
gender = Female;
imageurl = "https://foursquare.com/img/categories_v2/food/indian_";
lastlogin = "/Date(1378288646803+0000)/";
latitude = "22.27052139756";
lname = kanan;
longitude = "73.196614980698";
name = "Green Chillies";
photopath1 = "";
time = "/Date(1378288744627+0000)/";
userid = 202;
},
{
Distance = "2.08";
address = Manjalpur;
dob = "09-04-1986 ";
email = "kan#t.com";
facebookid = "";
fname = kanan;
gender = Female;
imageurl = "https://ss1.4sqi.net/img/categories_v2/food/indian_";
lastlogin = "/Date(1378288646803+0000)/";
latitude = "22.27052139756";
lname = kanan;
longitude = "73.196614980698";
name = "Green Chillies";
photopath1 = "";
time = "/Date(1378288744627+0000)/";
userid = 202;
},
{
Distance = "2.12";
address = Manjalpur;
dob = "03-11-1983";
email = "r#tax.com";
facebookid = 100001835956323;
fname = Rohan;
gender = Female;
imageurl = "https://foursquare.com/img/categories_v2/building/apartment_";
lastlogin = "/Date(1385115357020+0000)/";
latitude = "22.270002988846";
lname = Panchal;
longitude = "73.197391863176";
name = "Tulsidham circle";
photopath1 = "http://taxsmart.in/FTP_Data/S55_2.jpg";
time = "/Date(1381412082083+0000)/";
userid = 55;
},
{
Distance = "2.12";
address = Manjalpur;
dob = "03-11-1983";
email = "r#tax.com";
facebookid = 100001835956323;
fname = Rohan;
gender = Female;
imageurl = "https://ss1.4sqi.net/img/categories_v2/building/apartment_";
lastlogin = "/Date(1385115357020+0000)/";
latitude = "22.270002988846";
lname = Panchal;
longitude = "73.197391863176";
name = "Tulsidham circle";
photopath1 = "http://taxsmart.in/FTP_Data/S55_2.jpg";
time = "/Date(1381412082083+0000)/";
userid = 55;
}
)
my NSDictionary *finalResult print this result
Actually there are only two records but from web service I am getting
this type of result they cannot distinct because of unique imageurl.
so how can i remove duplicate data set.The same user data are only differ from each other with key imageurl.
I just want only single record of user does not matter which one(any one). So finally I will get only two record
//You can filter you response like this:
//tempArray is data array which content webservice response
NSMutableArray *mainArray = [[NSMutableArray alloc]init];
for (int i = 0; i< [temprray count]; i ++) {
if ([mainArray count]==0) {
[mainArray addObject:[temprray objectAtIndex:0]];
}
else {
NSDictionary *tempDict = [temprray objectAtIndex:i];
BOOL isRecordFound = NO;
for (int j = 0; j < [mainArray count]; j++) {
NSDictionary *tempinnerDict = [mainArray objectAtIndex:j];
if ([[tempinnerDict valueForKey:#"userid"] integerValue] == [[tempDict valueForKey:#"userid"] integerValue]) {
isRecordFound = YES;
break;
}
}
if (!isRecordFound) {
[mainArray addObject:tempDict];
}
}
}
It may be a webservice error. Best way is to contact web team or you can remove the duplicates by using below way
You can check the duplicate dictionary with the below method
- (BOOL)isEqualToDictionary:(NSDictionary *)otherDictionary
Inside a for loop you can check the duplicates and if there anyone, you can remove it from an NSMutableArray using
- (void)removeObjectAtIndex:(NSUInteger)index
I receive and array of dictionaries from a JSON feed and assign it to an NSMutableArray called jsonArray i.e:
jsonArray = [deserializedData objectForKey:#"reports"];
The feed looks like this:
reports = (
{
address = "The street";
email = "alex#blah.co.uk";
"eng_id" = 1;
"eng_name" = "Alex McPherson";
"eng_thumb" = "http://someurl/image/1.png";
form = Test;
id = 59;
lat = "51.1438330";
live = 1;
lng = "0.8693330";
location = "17 Victoria Crescent, Ashford, TN23 7HL";
name = "Alex McPherson";
phone = 01233000000;
rid = "A5C963-C95B-C3D639";
title = "#A5C963-C95B-C3D639, Litter";
tm = "2013-04-28 20:44:20";
type = 5;
"type-text" = "Litter";
},
{
address = "The street";
email = "alex#blah.co.uk";
"eng_id" = 2;
"eng_name" = "Rob Burt";
"eng_thumb" = "http://someurl/image/1.png";
form = Test;
id = 122;
lat = "51.1415000";
live = 1;
lng = "0.8715000";
location = "38 Beaver Road, Ashford, TN23 7RP";
name = Alex;
phone = 01233000000;
rid = "5A5C96-9072-6BAFA9";
title = "#5A5C96-9072-6BAFA9, Litter";
tm = "2013-04-28 20:35:56";
type = 8;
"type-text" = "Litter";
};
what I would like to do is insert a new value for key lets say into this jsonArray: distance = "0.16km" but my brain is just not working tonight....
so the new jsonArray should looks like this with the added key value mentioned above:
reports = (
{
address = "The street";
email = "alex#blah.co.uk";
"eng_id" = 1;
"eng_name" = "Alex McPherson";
"eng_thumb" = "http://someurl/image/1.png";
form = Test;
id = 59;
lat = "51.1438330";
live = 1;
lng = "0.8693330";
distance = "0.16km";
location = "17 Victoria Crescent, Ashford, TN23 7HL";
name = "Alex McPherson";
phone = 01233000000;
rid = "A5C963-C95B-C3D639";
title = "#A5C963-C95B-C3D639, Litter";
tm = "2013-04-28 20:44:20";
type = 5;
"type-text" = "Litter";
},
{
address = "The street";
email = "alex#blah.co.uk";
"eng_id" = 2;
"eng_name" = "Rob Burt";
"eng_thumb" = "http://someurl/image/1.png";
form = Test;
id = 122;
lat = "51.1415000";
live = 1;
lng = "0.8715000";
distance = "2.13km";
location = "38 Beaver Road, Ashford, TN23 7RP";
name = Alex;
phone = 01233000000;
rid = "5A5C96-9072-6BAFA9";
title = "#5A5C96-9072-6BAFA9, Litter";
tm = "2013-04-28 20:35:56";
type = 8;
"type-text" = "Litter";
};
basically I have a calculation that takes the long and lat from the feed and works out how far the poi is from my current location of which then I sort the array by using a sort descriptor based on the distance key that I want to insert above. I have the code for this just stuck on inserting into the existing nsmutablearray above
Read the deserialized JSON array as an NSArray (not NSMutableArray).
Then create a mutable copy of that array using something like:
NSMutableArray *mutableArray = [originalArray mutableCopy];
Then insert items into mutableArray.