langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
81
Task/JSON/NetRexx/json-2.netrexx
Normal file
81
Task/JSON/NetRexx/json-2.netrexx
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
import com.google.gson.
|
||||
import java.util.List
|
||||
|
||||
/**
|
||||
* Using google-gson library
|
||||
*
|
||||
* @see https://code.google.com/p/google-gson/
|
||||
*/
|
||||
class RJson02 public
|
||||
|
||||
properties private constant
|
||||
JSON_DWARFS = '' -
|
||||
'{\n' -
|
||||
' "title" : "Snow White and the Seven Dwarfs",\n' -
|
||||
' "year" : 1937,\n' -
|
||||
' "medium": "film",\n' -
|
||||
' "dwarfs": [ "Grumpy", "Happy", "Sleepy", "Bashful", "Sneezy", "Dopey", "Doc" ]\n' -
|
||||
'}'
|
||||
|
||||
/**
|
||||
* A bean that looks like the following JSON
|
||||
* <pre>
|
||||
* {
|
||||
* "title" : "Snow White & the Huntsman",
|
||||
* "year" : 2012,
|
||||
* "medium" : "film",
|
||||
* "dwarfs" : [ "Beith", "Quert", "Muir", "Coll", "Duir", "Gus", "Gort", "Nion" ]
|
||||
* }
|
||||
* </pre>
|
||||
*/
|
||||
SAMPLE_BEAN = RJSON02.DwarfBean( -
|
||||
/*"F2012_2",*/ -
|
||||
"Snow White and the Huntsman", -
|
||||
Long(2012), -
|
||||
"film", -
|
||||
Arrays.asList([String "Beith", "Quert", "Muir", "Coll", "Duir", "Gus", "Gort", "Nion"]) -
|
||||
)
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method main(args = String[]) public static
|
||||
gsonObj = GsonBuilder().setPrettyPrinting().create()
|
||||
jsonBean = RJson02.DwarfBean gsonObj.fromJson(JSON_DWARFS, RJson02.DwarfBean.class)
|
||||
say JSON_DWARFS
|
||||
say jsonBean.toString()
|
||||
say
|
||||
|
||||
json = gsonObj.toJson(SAMPLE_BEAN);
|
||||
say json
|
||||
say SAMPLE_BEAN.toString()
|
||||
say
|
||||
|
||||
return
|
||||
|
||||
-- =============================================================================
|
||||
class RJson02.DwarfBean public binary
|
||||
properties indirect
|
||||
title = String
|
||||
year = Long
|
||||
medium = String
|
||||
dwarfs = List
|
||||
|
||||
method DwarfBean(title_ = String null, year_ = Long null, medium_ = String null, dwarfs_ = List null) public
|
||||
setTitle(title_)
|
||||
setYear(year_)
|
||||
setMedium(medium_)
|
||||
setDwarfs(dwarfs_)
|
||||
return
|
||||
|
||||
method toString public returns String
|
||||
ts = StringBuilder()
|
||||
ts.append(String.format("%s@%08x ", [Object this.getClass().getSimpleName(), Integer(hashCode())]))
|
||||
ts.append('[')
|
||||
ts.append('title='String.valueOf(getTitle())', ')
|
||||
ts.append('year='String.valueOf(getYear())', ')
|
||||
ts.append('medium='String.valueOf(getMedium())', ')
|
||||
ts.append('dwarfs='String.valueOf(getDwarfs()))
|
||||
ts.append(']')
|
||||
return ts.toString()
|
||||
Loading…
Add table
Add a link
Reference in a new issue