‏إظهار الرسائل ذات التسميات extract. إظهار كافة الرسائل
‏إظهار الرسائل ذات التسميات extract. إظهار كافة الرسائل

الأحد، 5 يناير 2014

Sunlight Foundation json data - how to extract the values

up vote 0 down vote favorite

I'm experimenting with Sunlight Foundation Capitol words API and Webpy.

I'm able to retrieve the data from sunlight and store the results in a Webpy variable ($data) which is pass to the template.

It is possible to pass a templetor (webpy template system) variable to a Javascript and extract the results values?

I found a couple of JSON lectures and videos which I tried but so far can make it happen. I think that I might need to write the data into a JSON file before I could use it but at the same time I question myself because the results from sunlight are already formatted as JSON.

Here are two objects from the results: It would be a great help if some one could suggest how to manage this JSON with a Javascript or provide some options. Thanks in advance

{ "num_found": 78682, "results": [ { "speaker_state": "OH", "speaker_first": "Tim", "congress": 110, "title": "30-SOMETHING WORKING GROUP", "origin_url": "http://origin.www.gpo.gov/fdsys/pkg/CREC-2007-03-26/html/CREC-2007-03-26-pt1-PgH3071-2.htm", "number": 52, "order": 13, "volume": 153, "chamber": "House", "session": 1, "id": "CREC-2007-03-26-pt1-PgH3071-2.chunk13", "speaking": [ "Civil war." ], "capitolwords_url": "http://capitolwords.org/date/2007/03/26/H3071-2_30-something-working-group/", "speaker_party": "D", "date": "2007-03-26", "bills": null, "bioguide_id": "R000577", "pages": "H3071-H3078", "speaker_last": "Ryan", "speaker_raw": "mr. ryan of ohio" }, { "speaker_state": null, "speaker_first": null, "congress": 110, "title": "[Filed on January 4, 2007]", "origin_url": "http://origin.www.gpo.gov/fdsys/pkg/CREC-2007-01-05/html/CREC-2007-01-05-pt1-PgH110.htm", "number": 2, "order": 57, "volume": 153, "chamber": "House", "session": 1, "id": "CREC-2007-01-05-pt1-PgH110.chunk57", "speaking": [ "Service and the Naval Transport Service) during World War II; " ], "capitolwords_url": "http://capitolwords.org/date/2007/01/05/H110_filed-on-january-4-2007/", "speaker_party": null, "date": "2007-01-05", "bills": null, "bioguide_id": null, "pages": "H110-H123", "speaker_last": null, "speaker_raw": "recorder" }]

}


View the original article here

الثلاثاء، 24 ديسمبر 2013

How to extract image from JSON response in iOS

For extercating the Photo name from the JASON response you can use this code

JSONResponse : [ { "photo": "23_841676772.jpg", "date": "2013-06-06 08:11:15", "tags": "", "ID_article": "1", "commentcount": "5" },]

Make a Array object in .h file

@interface ViewController : UIViewController{ NSMutableArray * photoNameData;}

And in .m file

photoNameData =[[NSMutableArray alloc] init];NSMutableArray * tmpAry = JSONResponse;if (tmpAry.count !=0) { for (int i=0; iAnd than in Your cell code

if (photoNameData.count !=0) { cell.blogImageView.image = [UIImage imageNamed:[photoNameData objectAtIndex:indexPath.row]];}


You can use the code below to download the image in document directory.

//First check that document directory contain image or not NSString* tmpImgURL = @"http://www.my server.com/web_services/photos/23_841676772.jpg"; //for the image you need URL NSString* tmpStr = @"23_841676772.jpg"; //You can use code above to get image name NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documents = [paths objectAtIndex:0]; NSString* foofile = [documents stringByAppendingPathComponent:tmpStr]; BOOL imageExists = [[NSFileManager defaultManager] fileExistsAtPath:foofile];// if image not exist than download it if (!imageExists) { NSLog(@"%@ not exist",tmpImgURL); NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:tmpImgURL] cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:10.0]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *err){ if (!err && data) { //NSLog(@"data : %@",data); NSString *finalPath = [documents stringByAppendingPathComponent:tmpStr]; NSLog(@"finalPath : %@",finalPath); [data writeToFile:finalPath atomically:YES]; }else{ NSLog(@"err : %@",err); } }]; }

And you can use this image using this code..

NSString* tmpStr = @"23_841676772.jpg"; //You can use code above to get image nameNSString * documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];UIImage * image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",documentsDirectoryPath, tmpStr]];

View the original article here