Minor changes + cosmetics
Added conversion from STRING to JSON_STRING to help users.
This commit is contained in:
@@ -8,7 +8,7 @@ note
|
|||||||
class EJSON
|
class EJSON
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
{NONE} EXCEPTIONS
|
EXCEPTIONS
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
@@ -91,8 +91,6 @@ feature -- Access
|
|||||||
ll: LINKED_LIST [detachable ANY]
|
ll: LINKED_LIST [detachable ANY]
|
||||||
t: HASH_TABLE [detachable ANY, STRING_GENERAL]
|
t: HASH_TABLE [detachable ANY, STRING_GENERAL]
|
||||||
keys: ARRAY [JSON_STRING]
|
keys: ARRAY [JSON_STRING]
|
||||||
s32: STRING_32
|
|
||||||
s: detachable STRING_GENERAL
|
|
||||||
do
|
do
|
||||||
if a_value = Void then
|
if a_value = Void then
|
||||||
Result := Void
|
Result := Void
|
||||||
@@ -119,8 +117,7 @@ feature -- Access
|
|||||||
Result := jn.item.to_double
|
Result := jn.item.to_double
|
||||||
end
|
end
|
||||||
elseif attached {JSON_STRING} a_value as js then
|
elseif attached {JSON_STRING} a_value as js then
|
||||||
create s32.make_from_string (js.item)
|
create {STRING_32} Result.make_from_string (js.item)
|
||||||
Result := s32
|
|
||||||
elseif attached {JSON_ARRAY} a_value as ja then
|
elseif attached {JSON_ARRAY} a_value as ja then
|
||||||
from
|
from
|
||||||
create ll.make
|
create ll.make
|
||||||
@@ -140,9 +137,9 @@ feature -- Access
|
|||||||
until
|
until
|
||||||
i > keys.upper
|
i > keys.upper
|
||||||
loop
|
loop
|
||||||
s ?= object (keys [i], Void)
|
if attached {STRING_GENERAL} object (keys [i], Void) as s then
|
||||||
check s /= Void end
|
|
||||||
t.put (object (jo.item (keys [i]), Void), s)
|
t.put (object (jo.item (keys [i]), Void), s)
|
||||||
|
end
|
||||||
i := i + 1
|
i := i + 1
|
||||||
end
|
end
|
||||||
Result := t
|
Result := t
|
||||||
@@ -268,45 +265,4 @@ feature {NONE} -- Implementation (JSON parser)
|
|||||||
create Result.make_parser ("")
|
create Result.make_parser ("")
|
||||||
end
|
end
|
||||||
|
|
||||||
feature {NONE} -- Implementation (Basic Eiffel objects)
|
|
||||||
|
|
||||||
a_boolean: BOOLEAN
|
|
||||||
|
|
||||||
an_integer_8: INTEGER_8
|
|
||||||
|
|
||||||
an_integer_16: INTEGER_16
|
|
||||||
|
|
||||||
an_integer_32: INTEGER_32
|
|
||||||
|
|
||||||
an_integer_64: INTEGER_64
|
|
||||||
|
|
||||||
a_natural_8: NATURAL_8
|
|
||||||
|
|
||||||
a_natural_16: NATURAL_16
|
|
||||||
|
|
||||||
a_natural_32: NATURAL_32
|
|
||||||
|
|
||||||
a_natural_64: NATURAL_64
|
|
||||||
|
|
||||||
a_real_32: REAL_32
|
|
||||||
|
|
||||||
a_real_64: REAL_64
|
|
||||||
|
|
||||||
an_array: ARRAY [ANY]
|
|
||||||
once
|
|
||||||
Result := <<>>
|
|
||||||
end
|
|
||||||
|
|
||||||
a_character: CHARACTER
|
|
||||||
|
|
||||||
a_string_8: STRING_8
|
|
||||||
once
|
|
||||||
Result := ""
|
|
||||||
end
|
|
||||||
|
|
||||||
a_string_32: STRING_32
|
|
||||||
once
|
|
||||||
Result := {STRING_32} ""
|
|
||||||
end
|
|
||||||
|
|
||||||
end -- class EJSON
|
end -- class EJSON
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ inherit
|
|||||||
create
|
create
|
||||||
make_json
|
make_json
|
||||||
|
|
||||||
|
convert
|
||||||
|
make_json ({STRING})
|
||||||
|
|
||||||
feature {NONE} -- Initialization
|
feature {NONE} -- Initialization
|
||||||
|
|
||||||
make_json (an_item: STRING)
|
make_json (an_item: STRING)
|
||||||
@@ -92,7 +95,7 @@ feature -- Status report
|
|||||||
|
|
||||||
feature {NONE} -- Implementation
|
feature {NONE} -- Implementation
|
||||||
|
|
||||||
escaped_json_string (s: STRING): STRING
|
escaped_json_string (s: READABLE_STRING_8): STRING
|
||||||
-- JSON string with '"' and '\' characters escaped
|
-- JSON string with '"' and '\' characters escaped
|
||||||
require
|
require
|
||||||
s_not_void: s /= Void
|
s_not_void: s /= Void
|
||||||
|
|||||||
Reference in New Issue
Block a user