![]() |
#41 |
Junior Member
Join Date: Oct 2012
Posts: 36
|
That was just an example of the JSON object in memory (as valid Javascript rather than JSON), not the string passed to nsJSON to build it. The point was the /keys feature request.
|
![]() |
![]() |
![]() |
#42 |
Junior Member
Join Date: Oct 2012
Posts: 36
|
I have also found another case where nsJSON::Get does not return anything on the stack:
If you try to get something that doesn't exist (e.g. the specified /tree does not exist) Please can this be changed to return empty string, to avoid stack corruption? And I think that nsJSON: ![]() |
![]() |
![]() |
![]() |
#43 |
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
The plug-in will set the error flag if the tree or node does not exist. If you think it is possible the tree or node may not exist, you should check the error flag before reading from the stack. Remember to clear the error flag first if necessary. The error flag is the only way to distinguish a definite error.
I have implemented /keys and fixed the Delete crash but I am working on a new feature for console application execution for JSON input/output so will upload a new version when done. Stu |
![]() |
![]() |
![]() |
#44 |
Junior Member
Join Date: Oct 2012
Posts: 36
|
Awesome, thanks Stu!
|
![]() |
![]() |
![]() |
#45 |
Junior Member
Join Date: Oct 2012
Posts: 36
|
Just discovered another crash, not sure if this is related to the previous crash in Delete:
nsJSON::Set /tree testTree testNode /value testValue nsJSON::Get /tree testTree /exists /end Pop $R0 MessageBox MB_OK $R0 ; "yes" nsJSON::Delete /tree testTree /end ; CRASH |
![]() |
![]() |
![]() |
#46 |
Junior Member
Join Date: Oct 2012
Posts: 36
|
I'm also having trouble using the unicode version of the plugin:
code: With the ansi version, the message box reads "testValue" as expected, but with the unicode version is just says "t". |
![]() |
![]() |
![]() |
#47 | |
Major Dude
Join Date: May 2005
Location: New Zealand
Posts: 923
|
Quote:
By the way, if the plugins are copied correctly to both '${NSISDIR}\plugins\x86-ansi' and '${NSISDIR}\plugins\x86-unicode', then you don't need to use !addplugindir. 'Unicode True' does that work for you. "Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me) NSIS 3 POSIX Ninja Wiki Profile |
|
![]() |
![]() |
![]() |
#48 |
Junior Member
Join Date: Oct 2012
Posts: 36
|
Nope, confirmed I am using the correct builds. DLLs are stored in local plugins directory, not in NSISDIR, hence the use of addplugindir. Does this work for you?
|
![]() |
![]() |
![]() |
#49 |
Major Dude
Join Date: May 2005
Location: New Zealand
Posts: 923
|
No it doesn't work for me, it's showing the same as what you are getting.
"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me) NSIS 3 POSIX Ninja Wiki Profile |
![]() |
![]() |
![]() |
#50 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
When something in a ANSI installer is unexpectedly a single character then it is a clear indication that something was not converted from Unicode to ANSI. The other way around could be anything, a plugin mismatch or bug. A missing conversion bug to Unicode usually looks Chinese.
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#51 | |
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Quote:
I am still working on the process exec code. Stu |
|
![]() |
![]() |
![]() |
#52 |
Junior Member
Join Date: Oct 2012
Posts: 36
|
Yep, Unicode works fine now, thanks Stu.
I have another feature request: It would be great if /index accepted negative numbers to get/set/delete from the end of an array/node. For example, /index -1 means the last element, /index -2 means the second-last element and so on. Right now, this is achieved by getting the count of elements, decrementing, then getting/setting/deleting the required element. A negative index would streamline this process. |
![]() |
![]() |
![]() |
#53 | |
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Quote:
Stu |
|
![]() |
![]() |
![]() |
#54 |
Junior Member
Join Date: Feb 2014
Posts: 2
|
Output NodePath not cleared when response is empty?
Hi Stu,
started using nsJSON recently, very nice work! I'm facing an issue using HTTP web requests: code: The REST method I'm calling in the "Url" may have an empty response (e.g. only returns 200 OK). In such case, the returned Response tree has the "Output" node populated with the response from the previous call to another REST method, instead of returning an empty "Output" node. Is this a bug or am I missing something? Thanks Andrea |
![]() |
![]() |
![]() |
#55 |
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
I have uploaded a new version which fixes the issue.
http://nsis.sourceforge.net/File:NsJSON.zip Stu |
![]() |
![]() |
![]() |
#56 |
Junior Member
Join Date: Oct 2012
Posts: 36
|
I'm having a problem with the latest build where nsJSON::Serialize is leaving the filepath on the stack. I know there was an issue fixed recently where one too many values were popped but now the reverse seems to be true...
I suspect that the old code was always popping file, even if it wasn't needed, whereas the new code pushes it back on the stack even if it was needed On a separate note, I have found that doing an http request with Verb=POST and DataType=JSON sends a request where the post data is unicode with Content-Type: application/x-www-form-urlencoded Is there a way to get this to send as UTF-8 with Content-Type: application/json ? Thanks Last edited by Marshallx7; 2nd November 2016 at 00:20. Reason: extra request |
![]() |
![]() |
![]() |
#57 | ||||
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
How are you supposed to delete a tree? Especially the "default"? tree?
Quote:
Quote:
Quote:
Quote:
IntOp $PostCount $PostCount + 1 |
||||
![]() |
![]() |
![]() |
#58 |
Junior Member
Join Date: Oct 2017
Posts: 1
|
Good job!
Try this tool: JSON formatter |
![]() |
![]() |
![]() |
#59 | ||
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
Quote:
Quote:
Anders, please let me know if this resolves all your issues. Apologies for the wait. This will delete the root node and tree: code: Stu |
||
![]() |
![]() |
![]() |
#60 |
Junior Member
Join Date: Oct 2012
Posts: 36
|
I'm having a problem with the latest version (1.1.1.0)
code: To be clear, the previous version of the plugin (1.1.0.9) gives "yes" for the first snippet, as expected. |
![]() |
![]() |
![]() |
#61 |
Senior Member
Join Date: Nov 2013
Location: Iran
Posts: 343
|
![]()
hi
i read a json value from variable but i have some problems: this code can't show result value address: HTML Code:
StrCpy $0 '{"status":"ok","username":"rose","password":"software","expire":"2020","used_time":[],"address":"http:\/\/google.com\/apps"}' nsJSON::Set /value $0 nsJSON::Get "address" /end Pop $R0 DetailPrint $R0 but this code show result value address: HTML Code:
StrCpy $0 '{"status":"ok","username":"rose","password":"software","expire":"2020","used_time":"[]","address":"http:\/\/google.com\/apps"}' nsJSON::Set /value $0 nsJSON::Get "address" /end Pop $R0 DetailPrint $R0 HTML Code:
The difference in codes is [] and is "[]" but if in variable not insert [] to quotation then result can't successfully displayed |
![]() |
![]() |
![]() |
#62 | |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
Can't handle empty objects?
Quote:
IntOp $PostCount $PostCount + 1 |
|
![]() |
![]() |
![]() |
#63 |
Junior Member
Join Date: Jan 2008
Posts: 21
|
It fails to read Unicode JSON files in ANSI setup! (/Unicode tag only works in Unicode setup builds)
https://nsis.sourceforge.io/File:NsJSON.zip I've now checked the previous version and it does not have this problem! |
![]() |
![]() |
![]() |
#64 |
Junior Member
Join Date: Jan 2008
Posts: 21
|
some more detail for an ANSI setup;
NsJSON v1.1.0.6 is right version for these; nsJSON::Set /file /Unicode (Don't work in v1.1.1.0) nsJSON::Serialize /format /file /Unicode (Don't work both in v1.1.1.0 and 1.1.0.9) |
![]() |
![]() |
![]() |
#65 | |
Major Dude
|
@Afrow: In the most recent version there is a small bug:
If there is an empty array like this: Quote:
Edit: Quick fix is to update the function with another if condition: static struct JSON_NODE* EatNode(PTCHAR pszBuffer, int* piPos, BOOL bIsValue) PHP Code:
Cool looking installers with custom design: www.graphical-installer.com Create Setup Pages easily: www.install-designer.com Build installers in Visual Studio 2005-2022: www.visual-installer.com or RAD Studio 2009 - 11 Alexandria: www.rad-installer.com Last edited by T.Slappy; 29th January 2021 at 10:25. Reason: Added fixed code |
|
![]() |
![]() |
![]() |
#66 |
Junior Member
Join Date: Mar 2022
Posts: 3
|
Could someone point me in the right direction on this?
I'm trying to load JSON from GitHub's API, but the response I'm getting in the output file is: PHP Code:
Leaves me confused as to where exactly I'm going wrong. I've read and re-read the ReadMe and HttpWebRequest.nsi example file, I've checked my var, tree names and paths and like the Response body - I'm drawing a blank. Test Script: PHP Code:
|
![]() |
![]() |
![]() |
#67 | |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
Quote:
IntOp $PostCount $PostCount + 1 |
|
![]() |
![]() |
![]() |
#68 | |
Junior Member
Join Date: Mar 2022
Posts: 3
|
Quote:
It appeared as though the tree had the body of the response under a node named "Output", so I prepended that to the path and tested again. As it currently stands, both Async or regular HTTP GET requests to that URL seem to produce a 200 (OK) response but an empty body. (even when serializing the tree immediately upon completion of the request) So far, I haven't been able to replicate that behaviour in a browser or using the Rested Firefox plugin to replicate the User-Agent and headers that nsJSON is sending - both the browser and the plugin return the expected information from GitHub's API. At this point I can only assume it's either some bug or I've overlooked something particularly silly, hence coming here to ask persons more knowledgeable and familiar with both NSIS and this plugin. *A big thanks to whoever edited my post to fix the code blocks by the way, I couldn't find an Edit option available to me. |
|
![]() |
![]() |
![]() |
#69 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
From a quick look at the code, it looks like you can set "Agent" to whatever you want. Perhaps Github wants a "Mozilla" in there? From a quick test in another tool it looks like Github does not care much about the UA.
Do you have access to a web server when you can put a json file for testing? I have never used this plug-in to read directly from the web so I don't know much about that part. As a last resort, use INetC to download to $pluginsdir and then parse that file. IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#70 | |
Junior Member
Join Date: Mar 2022
Posts: 3
|
Quote:
I'm leaning towards the INetC plugin too, since we already use it to download the binaries, but I'm unsure how to parse the body of a GET response as a string rather than persisting it on disk. (I'm refactoring the installer away from hardcoded values that have to be manually updated and trying to minimise needless disk writes since a lot of our users are likely to be running SSDs as their primary drive.) Thanks for bearing with me on this, it's been an interesting but long overdue first foray into NSIS. looks like it may be a similar issue to the ones Ahmett linked in Post 64. Swapping to that version gave me partial output, but it looks like the response is getting cut off part way through the "assets_url" node of the reply. I'll keep digging. |
|
![]() |
![]() |
![]() |
#71 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
I don't think storing a small JSON file on a SSD is going to hurt it much. Windows writes a lot more to the drive just in daily use.
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#72 |
Junior Member
Join Date: Feb 2009
Location: Australia
Posts: 7
|
I also have been trying to hit a simple api with a json POST and get a json response.
I experimented for quite a while and was always getting "Output":{} as reported by Minother. Testing was based on using Postman with the same json POST to the same server, and it was giving a proper json response. At last I tried setting "RawOutput": true This now gives me something closer... at least the Output node is now a string that resembles the correct/desired json response. Two catches... 1. All the quotes (") in the Output node are now escaped as \" 2. Even when I try to remove these \ characters, it isn't quite right. It appears to be truncating the first of what should be two subnodes, and the {} are now mismatched. Here's the (edited) sample output with the \" turned into " and some linefeeds added to make reading easier.... { "Output": "{ "License":{ "SyncTime":"2022-03-25T00:43:34", "Status":"Active", "Expiry":"2022-05-02T00:00:00", "UserID":"900000", "Level":"-16641", "MaxVer":"3072", "AccNum":"XXXXX", "AccName":"YYYYYYYYYY YYYY", "AccEmail":"daveb@zzzzzzzzzz.com", "PCFinger":"4380FB1YYYYYYY", "StatusCode": 200 } Notice "Output": "{ etc... there is a spurious " before the opening {, and notice also, after "PCFinger":etc, it is just truncated and missing the rest of this node plus the whole of the next node. I really would like to read the response as json - it is valid json when I get it in a test using Postman. Certainly would be better to get the response as json, and be able to get subnodes etc. But as reported by Minother above, if I turn off RawOutput, I get an empty Output node with a correct "StatusCode": 200 in the response Any help appreciated.. I am new to using this nsJSON plugin which looks to be perfect for the job needed, if I could tame it... |
![]() |
![]() |
![]() |
#73 |
Junior Member
Join Date: Feb 2009
Location: Australia
Posts: 7
|
Some progress to report and a workaround in my case.
1. the truncation problem remains, and appears to be a limit of 256 characters in the POST response that appears in the "Output" node. 2. Still getting empty ouput {} unless I set "RawOutput" to true. This gives the \" escaped quotes, but *provided* the string is not truncated (ie <256 characters) then "Output" is a wellformed string with a closing quote and can be loaded in then json nodes extracted from the response. Here's a summary of what I did... this can possibly be simplified but is definitely working within these limitations (mainly the 256 character response limit): nsJSON::Set /tree HttpWebRequest /value `{ "Url": "${HttpWebRequestURL}", "Verb": "POST", "DataType": "JSON", "RawOutput": true }` nsJSON::Set /tree HttpWebRequest "Headers" "Authorization" /value "Basic QQQQQetc" ;....etc for other headers... nsJSON::Set /tree HttpWebRequest "Data" "MyPayloadKey1" /value `"$R0"` ; $R0 has some payload data ;....etc for other payload keys, then do the POST.... nsJSON::Set /tree HttpWebResponse /http HttpWebRequest ; check the response code nsJSON::Get /tree HttpWebResponse "StatusCode" /end Pop $R1 StrCmp $R1 "200" +1 badstatus ; extract the "Output" node as POST response nsJSON::Get /tree HttpWebResponse "Output" /end Pop $R1 nsJSON::Set /tree TheResponse /value `$R1` ; now we can look at the values of response keys like this nsJSON::Get /tree TheResponse "Message" /end ; this is the "Message" node in TheResponse Pop $R5 DetailPrint `Here is TheResponse.Message node: [$R5]` nsJSON::Get /tree TheResponse "AnotherResponseKey" /end Pop $R6 DetailPrint `Here is TheResponse.AnotherResponseKey node: [$R6]` ;....etc for other response nodes = = = = = = Note: I would have thought that providing a [Nodepath] as in the documentation would work, instead of first loading the "Output" node into another tree. Maybe that's due to dealing with the "RawOutput"? but this doesn't work... nsJSON::Get /tree HttpWebResponse "Output" "Message" /end Pop $R1 ...giving an empty string in $R1. I'm guessing that the problem is that the actual "Output" node is a quoted and escaped string, not a json node even though it converts nicely to json when handed in to this line of code... nsJSON::Set /tree TheResponse /value `$R1` So that's a summary of my workaround for the moment. Would be great if these two problems in nsJSON could be fixed... #1: 256 char limit to a POST response #2: support for "RawOutput": false ...so that the "Output" node is proper json, not a string like this "{\"key1\":\"value1\", etc... }" |
![]() |
![]() |
![]() |
#74 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,548
|
I tried contacting the author but no response so far.
IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
|
Tags |
json, plug-in |
Thread Tools | Search this Thread |
Display Modes | |
|
|