We have moved to a new Sailfish OS Forum. Please start new discussions there.
1

serialize deserialize json array to file [answered]

asked 2017-05-27 07:19:26 +0300

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

updated 2017-05-27 07:20:00 +0300

pawel gravatar image

hi for my app i would need a possibility to ser/deserialize a json array to / from file. i am using qml and java only in my app. not in mood to start with c++ again. it s just too long back. any suggestion ? thanks

edit retag flag offensive reopen delete

The question has been closed for the following reason "the question is answered, an answer was accepted" by pawel
close date 2017-07-29 12:13:57.546916

Comments

Do you want to write to a specific file or just save your json data?

michfu ( 2017-05-31 18:24:47 +0300 )edit

2 Answers

Sort by » oldest newest most voted
3

answered 2017-05-27 13:40:35 +0300

amica gravatar image

updated 2017-05-28 10:29:00 +0300

Hi, as you may know you can add JavaScript almost everywhere inside QML and for parsing and serializing JSON, JavaScript offers the JSON object, which is also supported in Qt, see http://doc.qt.io/qt-5/qtqml-javascript-functionlist.html#the-json-object

To load a file via its URL, have a look at http://www.mobilephonedevelopment.com/qt-qml-tips#File%20Access (which could be combined with http://doc.qt.io/qt-5/qml-qtquick-dialogs-filedialog.html)

edit flag offensive delete publish link more

Comments

i might have been not concrete enough, those two calls i know. and i use them to ser/deser but how to read / write to file ? all i did find was this http get example.

my current workaround is a variable in a js file.

pawel ( 2017-05-27 21:07:24 +0300 )edit

I am sorry, but I am inexperienced with file access. Maybe there is no JS-only approach to that. But perhaps that could be useful for you, when it is only about persistence and not necessarily about file access: http://doc.qt.io/qt-5/qtquick-localstorage-qmlmodule.html

amica ( 2017-05-27 21:42:21 +0300 )edit

thanks. i am already using db. my problem is now to populate the same with data.

pawel ( 2017-05-28 09:55:15 +0300 )edit

I updated my answer.

amica ( 2017-05-28 10:28:43 +0300 )edit

my main problem was to load and save, stringify was known to me. however i.took some code from ownkeepass to implement import, export

pawel ( 2017-07-29 12:13:33 +0300 )edit
1

answered 2017-05-27 15:51:28 +0300

coderus gravatar image

updated 2017-05-28 10:13:43 +0300

You can't read or write to files in QML/JS only. You can use PyOtherSide if you don't want to Qt.

edit flag offensive delete publish link more

Comments

ok, thanks and whatabout read ? however will google py

pawel ( 2017-05-28 09:56:12 +0300 )edit

I mean read or write.

coderus ( 2017-05-28 10:14:12 +0300 )edit

Question tools

Follow
1 follower

Stats

Asked: 2017-05-27 07:19:26 +0300

Seen: 646 times

Last updated: May 28 '17