![]() |
#1 |
Junior Member
Join Date: Oct 2020
Posts: 47
|
read json without nsjson
in NSIS, I don't find native JSON support and I cannot use nsjson plugin. I have to use string instructions to read a json property.
{ "DATE" : "****", "BUILD_NUMBER" : ***, "RELEASE_STRING" : "***" } How do I read these json properties and store these values in the variable |
![]() |
![]() |
![]() |
#2 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,505
|
StrCpy+StrLen+StrCmp in a custom parser.
Why can't you use a plug-in? IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#3 |
Junior Member
Join Date: Oct 2020
Posts: 47
|
plugin didnt work and last time in forum it was discussed it had some issues
|
![]() |
![]() |
![]() |
#4 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,505
|
Works just fine
PHP Code:
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#5 |
Junior Member
Join Date: Oct 2020
Posts: 47
|
I have a predetermined json file given like test.json which contains json properties. I cannot write it, but I am supposed to read values from predetermined json files. for that it does not work. if I have test.json in temp dir, i cannot read it.
|
![]() |
![]() |
![]() |
#6 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,505
|
And what does this non-working file look like?
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#7 |
Junior Member
Join Date: Oct 2020
Posts: 47
|
{
"DATE" : , "BUILD_NUM" : , "RELEASE_STR" : "" } ABove would be format of given json file |
![]() |
![]() |
![]() |
#8 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,505
|
That is not valid JSON. Empty values should be "", null, or not present at all.
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#9 |
Junior Member
Join Date: Oct 2020
Posts: 47
|
my fault...I wanted to hide few info. the file will be something like this
{ "DATE" : "2022-03-06 08:45:36 +0000", "BUILD_NUM" : "123", "RELEASE_STR" : "1234/56" } |
![]() |
![]() |
![]() |
#10 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,505
|
Again, just works just fine for me:
PHP Code:
Perhaps your file has a special encoding? UTF16? UTF8 with BOM? IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#11 |
Junior Member
Join Date: Oct 2020
Posts: 47
|
the code works. but the problem is DATE, BUILD, RELEASE values keep changing evry day and I wouldn't know what the values are to write it into text file. At run time in my installer, i have to read from a .json file and output it into my file.
|
![]() |
![]() |
![]() |
#12 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,505
|
Section "Prepare" is not something you would use in your .nsi, it is just there to generate a example JSON file. The other section only cares about the names, not the value.
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#13 |
Junior Member
Join Date: Oct 2020
Posts: 47
|
for some strange reasons, this does not seem to work for you. I could have attached my file. But there is no option to attach it.
|
![]() |
![]() |
![]() |
#14 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,505
|
There is a way to attach files. You might have to zip it.
Worst case, put a hex dump on pastebin. IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#15 |
Junior Member
Join Date: Oct 2020
Posts: 47
|
got to know the reason... I have a key/property with an empty value... because of empty value "ABC" : [], it is not showing other values as well
guess it does not support empty arrays. even in a single empty array, the plugin does not read the entire json file. that's unfortunate |
![]() |
![]() |
![]() |
#16 |
Junior Member
Join Date: Oct 2020
Posts: 47
|
Anders, can you please elaborate on StrCpy+StrLen+StrCmp for json files
|
![]() |
![]() |
![]() |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|