Parse this Json to NSmutablearray [closed] - ios

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i've this unique text plain
{"id":"AALI.NG","data":["AALI","NG",19312,0,0,0,0,0,0,0,0,0,0,0,70,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}
{"id":"AALI.RG","data":["AALI","RG",19500,0,0,0,0,0,0,0,0,0,0,0,26,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}
{"id":"AALI.TN","data":["AALI","TN",19500,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}
{"id":"ABBA.NG","data":["ABBA","NG",60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}
{"id":"ABBA.RG","data":["ABBA","RG",85,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}
{"id":"ABBA.TN","data":["ABBA","TN",85,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}
{"id":"ABDA.NG","data":["ABDA","NG",3500,0,0,0,0,0,0,0,0,0,0,0,6000,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}
then i change it to :
{"stockQuote":[{"id":"AALI.NG","data":["AALI","NG",19312,0,0,0,0,0,0,0,0,0,0,0,70,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"},
{"id":"AALI.RG","data":["AALI","RG",19500,0,0,0,0,0,0,0,0,0,0,0,26,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"},
{"id":"AALI.TN","data":["AALI","TN",19500,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"},
{"id":"ABBA.NG","data":["ABBA","NG",60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"},
{"id":"ABBA.RG","data":["ABBA","RG",85,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"},
{"id":"ABBA.TN","data":["ABBA","TN",85,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"},
{"id":"ABDA.NG","data":["ABDA","NG",3500,0,0,0,0,0,0,0,0,0,0,0,6000,0,0,0,0,0,0,0,0,0,0,0,0],"req":"SQ"}]}
basicly type of data i get from server is text/plain and i need to add {"stockQuote":[, "," and also }]} to make it like json...
the question is, how to parse it to json an NSMutableArray then i draw it to UITableView, how to do it?? should i change it to NSDictionary first and then insert it to NSMutableArray?

Your second JSON is just an NSDictionary with a single object that is an NSArray. So just take your normal array that you have in the first JSON, and do this:
NSArray *jsonArray = [jsonDic objectForKey:#"stockQuote"];
where jsonDic is your json's parse object with NSJSONSerialization method.

Related

How to create a simple API in Firebase? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have never worked on the backend and never created an API, all I know is to handle the JSON response, This doesn't help much, but I do not understand "PUT - Writing Data".
However, I just want to know that how can I create a simple dictionary of multiple arrays or key-values as rest API, So that it can be fetched and i can show the data in table view etc.
According to Firebase Documentations, if you wanna create a node on Firebase realtime database, you can simply set a value to any key you want. The value here should be NSDictionary.
This is the code you can refer to:
// create a new node
[[[_ref child:#"users"] child:user.uid] setValue:#{#"username": username}];
// you can also use update to create a new node
NSString *key = [[_ref child:#"posts"] childByAutoId].key;
NSDictionary *post = #{#"uid": userID,
#"author": username,
#"title": title,
#"body": body};
NSDictionary *childUpdates = #{[#"/posts/" stringByAppendingString:key]: post,
[NSString stringWithFormat:#"/user-posts/%#/%#/", userID, key]: post};
[_ref updateChildValues:childUpdates];
Hope it helps.

save string variable in NSMutableArray -Error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm new to iOS and its development. Here I'm passing string value to saveStringpath variable then I want to save it in type NSMutable array saveStrings but I'm getting:
thread 1 exc_bad_access (code=2 type breakspoint
please help me.
//here i need to save these data in NSMutable array
-(void)saveNSMutablearray:(NSString*)saveStringpath
{
//start Mutable array to save this values
NSMutableArray *saveStrings =[[NSMutableArray alloc]init];
[saveStrings addObject:saveStrings];
NSString *test = [saveStrings objectAtIndex:0];
NSLog(#"JSON:-----vm %#", test);
}
The problem you are facing is because of wrong variable name. In your code you are adding array into array, so to solve the problem please change this line:
[saveStrings addObject:saveStrings];
into that one:
[saveStrings addObject:saveStringpath];
and the problem is gone :)

display NSDictionary to uilables dynamic view [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I have to parse a complicated xml
http://clinicaltrials.gov/show/NCT01423929?displayxml=true
in this xml when I change id NCT01423929 then i got another xml and both of xml tags are not fixed there may be change in number of tag according id.
But I have a an xml schema for above xml
http://clinicaltrials.gov/ct2/html/images/info/public.xsd
for parsing i am using XMLConverter and XMLReader both are return me NSDictionary but I don't get that how to dynamic work with NSDictionary to display keys on left side UILabel and value for that key on right side UILabel I am attached a screen that
Please help and sorry for bad english
Thanks in advance
It's pretty simple as you parse the data from xml.
Lets say your Dictionary name is parseDictionary and it's look something like below..
parseDictionary:
{
"Responsible Party" = "Gilead Sciences";
"Start Date" = "September, 2013";
"Last Updated Date" = "August 20, 2013";
}
You have already did that. Now just do the below
NSArray *keyArray=[parseDictionary allKeys];
for(NSString *key in keyArray)
{
[leftLabel setText:key]; //set the key on the leftLabel
[rightLabel setText:[parseDictionary objectForKey:key]]; //set the value on right label.
}
NB:: For each and every loop it'll over right the values so you will get only the Last Updated Date and August 20, 2013. I am just showing you how to get the key with associated value. I guess you must use UITableView to show the data. So there will no problem for you.

parse json feeds using jsonkit iOS [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I'm trying to use the JSONKIt found here https://github.com/johnezang/JSONKit to parse through a JSON Feed and put into objective-c objects. I'm new at iOS and don't really know where to start. Are there any good tutorials for using this library?
After googling, I didn't find any tutorials but using JSONKit should be self explanatory.
After downloading your JSON feed using NSURLConnection or ASIHTTPRequest simply create a dictionary of all the objects in the JSON feed like so:
//jsonString is your downloaded string JSON Feed
NSDictionary *deserializedData = [jsonString objectFromJSONString];
//Helpful snippet to log all the deserialized objects and their keys
NSLog(#"%#", [deserializedData description]);
After creating a dictionary you can simply do something like this:
NSString *string = [deserializedData objectForKey:#"someJSONKey"];
And that is the basics behind JSONKit.
JSONKit is much more powerful of course, you can find some of the other things you can do with it in JSONKit.h
I would becareful about making the assumption that objectFromJSONString is returns an NSDictionary, it can very well return an array, or nil, especially if the server returns some rarely used and thought of error.
A more appropriate action would be:
NSError *error;
id rawData = [jsonString objectFromJSONStringWithParseOptions:JKParseOptionNone error:&error];
if ( error != nil ) {
// evaluate the error and handle appropriately
}
if ( [rawData isKindOfClass:[NSDictionary class]] ) {
// process dictionary
}
else if ( [rawData isKindOfClass:[NSArray class]] ) {
// process array
}
else {
// someting else happened, 'rawData' is likely 'nil'
// handle appropriately
}
Without these checks, you could very well end up with a runtime error because the server returned someting unexpected.

UIWebView - NSStringWithFormat [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to get a UIWebView working with the following code:
NSString *urlAddress = [NSString stringWithFormat: #"http://www.wikipedia.org/wiki/%#",recipe.name];
recipe.name is the entity and property from the core data model
I used NSLog to test the recipe.name and it is outputting correctly to the console
I tried this with just a plain URL and it works fine:
NSString *urlAddress = [NSString stringWithFormat: #"http://www.wikipedia.org/wiki/soup"];
Initialize your UIWebView.
Create an NSURL-object containing your url(using +[NSURL URLWithString:] for example).
Create an NSURLRequest-object with the created NSURL-object.
load the NSURLRequest in your webView.
Voila
:)

Resources