B4J Library the First b4x ORM framework

:Dtoday I have write some code to update the my toolkit (which modify from:https://www.b4x.com/android/forum/threads/server-online-json-tree-example.39048/)

json string:
{"image":"https:\/\/app.test.com\/Uploads\/touxiang\/2016-12-20\/5858e291028f7.jpg","jsname":"\u65e0\u540d\u6c0f","kc_title":"\u5927\u59d0\u59d0\u5965\u65701\u5bf91","id":"34","kc_id":"57","js_id":"1095","comment_huifu_id":"15","comment_content":"\u5475\u5475 \u6559\u7684\u4e0d\u9519\u5462 \u90fd\u542c\u61c2\u4e86","comment_id":"0","comment_type":"1","comment_xj":"0","comment_addtime":"2016-10-25 11:21:05","username":"\u51cc","usertel":"186********","city":"\u4e4c\u9c81\u6728\u9f50","nianji":"\u4e94\u5e74\u7ea7","riqi":" -","children":[{"id":"36","kc_id":"57","comment_huifu_id":"0","comment_content":"\u4e00\u8d77\u52a0\u6cb9\uff01","comment_id":"34","comment_addtime":"2016-10-25 15:14:07"}]}

generate by toolkit:
B4X:
Type typRoot(image As String,comment_xj As String,city As String,kc_title As String,comment_addtime As String,usertel As String,comment_id As String,nianji As String,comment_huifu_id As String,kc_id As String,children As List,comment_type As String,js_id As String,comment_content As String,riqi As String,id As String,jsname As String,username As String)

Sub parseStr2typRoot(str As String) As typRoot
    Dim parser As JSONParser
    parser.Initialize(str)
    Return map2typRoot(parser.NextObject)
End Sub
Sub map2typRoot(m As Map) As typRoot
    Dim ret As typRoot
    ret.Initialize
    ret.image=m.GetDefault("image","")
    ret.comment_xj=m.GetDefault("comment_xj","")
    ret.city=m.GetDefault("city","")
    ret.kc_title=m.GetDefault("kc_title","")
    ret.comment_addtime=m.GetDefault("comment_addtime","")
    ret.usertel=m.GetDefault("usertel","")
    ret.comment_id=m.GetDefault("comment_id","")
    ret.nianji=m.GetDefault("nianji","")
    ret.comment_huifu_id=m.GetDefault("comment_huifu_id","")
    ret.kc_id=m.GetDefault("kc_id","")
    ret.children=m.Get("children")
    ret.comment_type=m.GetDefault("comment_type","")
    ret.js_id=m.GetDefault("js_id","")
    ret.comment_content=m.GetDefault("comment_content","")
    ret.riqi=m.GetDefault("riqi","")
    ret.id=m.GetDefault("id","")
    ret.jsname=m.GetDefault("jsname","")
    ret.username=m.GetDefault("username","")
    Return ret
End Sub
usage:
B4X:
Dim js As String=$"{"image":"https:\/\/app.test.com\/Uploads\/touxiang\/2016-12-20\/5858e291028f7.jpg","jsname":"\u65e0\u540d\u6c0f","kc_title":"\u5927\u59d0\u59d0\u5965\u65701\u5bf91","id":"34","kc_id":"57","js_id":"1095","comment_huifu_id":"15","comment_content":"\u5475\u5475 \u6559\u7684\u4e0d\u9519\u5462 \u90fd\u542c\u61c2\u4e86","comment_id":"0","comment_type":"1","comment_xj":"0","comment_addtime":"2016-10-25 11:21:05","username":"\u51cc","usertel":"186********","city":"\u4e4c\u9c81\u6728\u9f50","nianji":"\u4e94\u5e74\u7ea7","riqi":" -","children":[{"id":"36","kc_id":"57","comment_huifu_id":"0","comment_content":"\u4e00\u8d77\u52a0\u6cb9\uff01","comment_id":"34","comment_addtime":"2016-10-25 15:14:07"}]}"$
Dim res As typRoot=parseStr2typRoot(js)
Log(res.city)

note:
1.the code dependson json library;
2.the toolkit dependson json+jserver library
3.open toolkit by b4j and run it(or compile it then run with command "java -jar xxx.jar"),then view http://127.0.0.1:88/;
4.using the code with kvs2 will be better

and you can find more from my github:https://github.com/icefairy/b4xlibs_tk
and ~ can you give me a star on this project?:p
:)
 

Attachments

  • ormtoolkit.zip
    42.8 KB · Views: 404
Last edited:
Top