JSON etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
JSON etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

20 Temmuz 2013 Cumartesi

ExtJS 4 Php JSON XML Örnekleri

ExtJS 4 ve Php ile xml ve json verikaynaklarından okuma işleminin nasıl yapılabileceğini gösteren kod örnekleridir.

Vakti zamanında çok derinliklerine kadar dalmıştım. :)
Kod örneklerine aşağıdaki adresten erişebilirsiniz.



https://github.com/ismailkocacan/ExtJS-4_Php_JSON_Ornekleri


25 Eylül 2012 Salı

Datasnap rest sunucusu ile iletişim(iOS Client)

Daha önce TDataset class'ına uzanım fonksiyonu olarak yazdığım ToJSONData isminde bir fonksiyonum vardı.Bu fonksiyon sayesinde veritabanında ki verileri kolayca json formatına çevirip dışarı sunabiliyordum.

Bu servislere de iOS ortamından erişmeyi görücez.

Person.h

@interface Person : NSObject
    @property(nonatomic) NSInteger rid;
    @property(nonatomic,retain) NSString *firstname;
    @property(nonatomic,retain) NSString *lastname;
@end

Person.m

#import "Person.h"

@implementation Person
  @synthesize rid;
  @synthesize firstname;
  @synthesize lastname;
@end

mainViewController.m

#import "mainViewController.h"
#import "Person.h"
#import "SBJson.h"

@interface mainViewController ()
  
@end

Person *person;
NSMutableArray * personlist;

@implementation mainViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
               
    personlist=[NSMutableArray new]; 
    NSURL *url = [[NSURL alloc] 
                  initWithString:@"http://192.168.1.7:8080/datasnap/rest/TServerMethods1/GetPersonList"];
    NSError *error = nil;
    NSStringEncoding encoding;
    NSString *rawjson = [[NSString alloc] initWithContentsOfURL:url
                                                   usedEncoding:&encoding 
                                                          error:&error];
    //formatting : [NSString stringWithFormat:@"%d", rawjson.length];
    if (rawjson.length!=0){
        SBJsonParser * parser=[SBJsonParser new];  
        NSDictionary *jsonObject = [parser objectWithString:rawjson error:&error];
    
        NSArray *mainlist = [jsonObject objectForKey:@"result"];
        NSArray *innerlist= [mainlist objectAtIndex:0];
        
        for (NSDictionary *item in innerlist) {
            person =[Person new];
            person.rid=[[item objectForKey:@"rid"] integerValue];
            person.firstname=[item objectForKey: @"firstname"]; 
            person.lastname=[item objectForKey: @"lastname"]; 
            [personlist addObject:person]; 
        }
    }
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsneSelectionOnViewWillAppear = NO;
 
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 //warning Incomplete method implementation.
    // Return the number of rows in the section.
    return [personlist count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    // Configure the cell...
    Person * personItem=[personlist objectAtIndex:indexPath.row]; 
    cell.textLabel.text=[NSString stringWithFormat:@"%@ %@",
                         [personItem firstname],[personItem lastname]];
    return cell;
}




Demo :





Kaynaklar :

http://json.org/
http://stig.github.com/json-framework/
http://docwiki.embarcadero.com/RADStudio/en/DataSnap_REST_Messaging_Protocol
http://jasarien.com/?p=428
http://stackoverflow.com/questions/4919249/how-to-parse-json-into-objective-c-sbjson
http://stackoverflow.com/questions/3995519/how-to-use-stringwithcontentsofurlencodingerror
http://stackoverflow.com/questions/12567491/how-to-parse-this-json-data-with-objective-c-sbjsonparser

Hadi hayırlı işler. :)

10 Eylül 2012 Pazartesi

TDataset ToJSONData

{ İsmail Kocacan }
unit uJsonHelper;

interface

uses

  Data.DB,
  System.SysUtils,
  Data.DBXJSON,
  Data.DBXJSONCommon,
  Data.DBXJSONReflect;

type

  TDatasetJSONHelper = class helper for TDataset
  public
    function ToJSONData: TJSONArray;
  end;

implementation

{ TDatasetJSONHelper }
function TDatasetJSONHelper.ToJSONData: TJSONArray;
var
  jso: TJSONObject;
  jsa: TJSONArray;
  jsp: TJsonPair;
  J: Integer;
begin
  Self.Open;
  jsa := TJSONArray.Create();
  while not Self.Eof do
  begin
    jso := TJSONObject.Create();
    for J := 0 to FieldCount - 1 do
      jso.AddPair(TJsonPair.Create(Fields[J].DisplayName, Fields[J].Value));
    jsa.AddElement(jso);
    Self.Next;
  end;
  Self.Close;
  Result := jsa;
end;

end.
TDataset sınıfına uzanım fonksiyonu olarak yazmamızın sebebi; TDataset sınıfı kullanılarak genişletilen(kalıtılan) üst sınıflarda da,kolayca kullanabilelim diyedir.
 Örneğin ;
 SQLQuery1.ToJSONData;
 ADOQuery1.ToJSONData;
 UniQuery1.ToJSONData;
 BilmemNeQuery1.ToJSONData;

 Şeklinde kullanabilmek mümkün olacaktır.
 Örnek Çıktı
{
 "result":
  [
   {"RID":"3","FIRSTNAME":"serdar","LASTNAME":"sezer"},
   {"RID":"2","FIRSTNAME":"kemal","LASTNAME":"bayat"},
   {"RID":"1","FIRSTNAME":"ismail","LASTNAME":"kocacan"}
  ]
}
Yukarıdaki çıktıyı alabilmek için bir takım düzenlemeler yapmak gerekiyor.Bu düzenlemeleri Datasnap REST Ve JSON Formatı Hakkında konusunda bulabilirsiniz.