android - Delphi XE5 RestClient and PHP generated JSON with boolean data types -


I'm making my first Android app with Delphi XE5.

PostgreSQL database running on an intranet in the data

Given that access to databases directly from mobile devices is not recommended, I provide Apache Web Server and PHP application have installed.

Everything is fine, but I have a problem with the boolean field:

This is a sample table:

  choose from resources *;  

and use the json_econder function to return data in json format:

  $ r = $ dbh- & gt; Query ($ sql); If ($ r) {$ f = $ r-> gt; all (); Echo json_encode ($ f); } ...  

The returned data is as follows:

  [{"" resource_id ": 1 , "0": 1, "resource_name": "lathe 01", "1": "lathe 01", "action": wrong, "2": wrong}, {"resource_id": 2, "0": 2 True, "2": true} {"resource_id": 3, "0": 3, "source_name": "lathe 02", "1": "lathe 02", "is_carnation"} {"resource_id": 3, "resource_name": "01 press Delphi Program contains the following components:  
    ", "1": "press 01", "ice_work": true, "2": true]] RESTClient1: TRESTClient1
  • RESTResponse1: RESTResponse
  • RestRequest1: TRestRequest
  • RESTResponseDataSetAdapter1: TRESTResponseDataSetAdapter
  • Clien RESOURCE_ID (ftInteger)
  • RESOURCE_NAME (ftString)
  • is_working:

    element RESTResponseDataSetAdapter1 I have created the necessary fields (FtBoolean)

    and I have updated the ClientDataSet1 fields for the RESTResponseDataSetAdapter1.

    If I run the app, then

      in the command 1.execeit; Exception has been raised: Invalid value debug mode two exceptions for  

    field 'is_working'

    In the type (boolean) type of type (UnicodeString) the version does not change cold '

    and then:

    There is an 'invalid value for field' in the adidax error message_working ''

    What went wrong?

    The problem is in the REST.Response.Adapter unit, enough to stop the callback for parsing your data in a dataset Are not

      process TCustomJSONDataSetAdapter.CB_CollectFieldDefs (constant AJSONObject: TJSONObject) ;. Var LJSneaker: TJSniper; Start in AJSONObject for LJSONPier, Start DoAddDataSetFieldDef (LJSONPair.JsonString.Value, ftString); End; End; // and process TCustomJSONDataSetAdapter.CB_CollectFieldDefs (const AJSONObject: TJSONObject); Var LJSneaker: TJSniper; Start in AJSONObject for LJSONPier, Start DoAddDataSetFieldDef (LJSONPair.JsonString.Value, ftString); End; End;  

    In your case CB_CollectFieldDefs is not called because you have manually created dataset field definitions. It should be parsed simple, but unfortunately this is not the case. The reason for this is that TJsonPair Boolean Jason does not correctly parse values ​​in TJsonObject. Until CB_CollectFieldData is called, all Boolean values ​​are empty string. Therefore we get the exception 'type (UnicodeString) type can not be converted into (bullion).'


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -