Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread How work with TReader?
Fri, Apr 22 2016 5:02 AMPermanent Link

Ashirov

Hi!

I have some JSON data from server, how parse their and use in my application?

{  
  "data":[  
     {  
        "id":42,
        "user_id":265,
        "msg_text":"Hi",
        "user_phone"Tongueone number,
        "user_name":"Make",
        "user_cityname":"Astana"
     },
     {  
        "id":43,
        "user_id":266,
        "msg_text":"Hi",
        "user_phone"Tongueone number,
        "user_name":"Bake",
        "user_cityname":"Astana"
     }
}

please give example how to use TParser, where set ARRAY_NAME for work with him.
Example i use ARRAY_NAME - "data"

thnx!
Fri, Apr 22 2016 8:17 AMPermanent Link

Mark Brooks

Slikware

Avatar

Fri, Apr 22 2016 8:39 AMPermanent Link

Matthew Jones

Mark Brooks wrote:

> which has worked well for me.

Me too. I posted some questions about this recently, but if you search
using the web interface for TReader etc then you will find all that is
needed.

--

Matthew Jones
Mon, Apr 25 2016 11:37 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Ashirov,

<< I have some JSON data from server, how parse their and use in my application? >>

Please post the class definition that you're trying to read this data into.

The Object Persistence example application covers the basics on how to do deal with reading/writing to/from JSON, but it doesn't cover array handling.

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Apr 28 2016 3:48 PMPermanent Link

Ashirov

Tim Young [Elevate Software] wrote:

Please post the class definition that you're trying to read this data into.

The Object Persistence example application covers the basics on how to do deal with reading/writing to/from JSON, but it doesn't cover array handling.
----------------------------------------------------------------

it works but for one object, how parse array with many objects, and have array name

{"id":"67","user_id":"591","msg_text":"some text","user_phone":"754546464","user_name":"Name","user_fname":"SecName ","candriver":"0","user_cityname":"City","ava":"def","city_id":"221","time_msg":"15:45:34","date_msg":"2016-04-28"}

type
  TPushObj = class(TPersistent)
  private
     fid, fuser_id, fmsg_text,
     fuser_phone, fuser_name, fuser_fname,
     fcandriver, fuser_cityname, fava, fcity_id, ftime_msg, fdate_msg: string;
  public
     procedure LoadFromJSON(const aJSON: string);
  published
     property id: string read fid write fid;
     property user_id: string read fuser_id write fuser_id;
     property msg_text: string read fmsg_text write fmsg_text;
     property user_phone: string read fuser_phone write fuser_phone;
     property user_name: string read fuser_name write fuser_name;
     property user_cityname: string read fuser_cityname write fuser_cityname;
     property candriver: string read fcandriver write fcandriver;
     property ava: string read fava write fava;
     property city_id: string read fcity_id write fcity_id;
     property time_msg: string read ftime_msg write ftime_msg;
     property date_msg: string read fdate_msg write fdate_msg;
  end;

procedure TPushObj.LoadFromJSON(const aJSON: string);
var
  R: TReader;
begin        
  R := TReader.Create;
  R.Initialize(aJSON);
  try
     Self.LoadArray(R);
  finally
     R.Free;
  end;
end;
Image