LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple JSON Error

Solved!
Go to solution

Here is the NXG block diagram that is throwing a JSON Error

DeOdderKeith_0-1595911556174.png

And I get this error in NXG

DeOdderKeith_3-1595911781984.png

String Constant is blank, and body contains this:

<Response><Terminal><Name>error out</Name><Value><Name>status</Name><Value>0</Value><Name>code</Name><Value>0</Value><Name>source</Name><Value></Value></Value></Terminal><Terminal><Name>string</Name><Value>{&quot;0&quot;:&quot;First&quot;}</Value></Terminal></Response>

 

 

 

And here is the LV2017 WEB Service that is supposed to respond with a String.

DeOdderKeith_1-1595911643358.png

The service does put the correct JSON string out

DeOdderKeith_2-1595911699912.png

 

Help !!

 

Keith

 

0 Kudos
Message 1 of 3
(2,694 Views)
Solution
Accepted by topic author DeOdderKeith

@DeOdderKeith wrote:

And I get this error in NXG

Hi, DeOdderKeith!

 

Per the error code that I looked up via Google,

−375003 The JSON string is invalid. JSON strings must be encoded in UTF-8 and must conform to the JSON grammar.

 

Looks like the returned string doesn't confirm to JSON grammar.

 


@DeOdderKeith wrote:

String Constant is blank, and body contains this:

<Response><Terminal><Name>error out</Name><Value><Name>status</Name><Value>0</Value><Name>code</Name><Value>0</Value><Name>source</Name><Value></Value></Value></Terminal><Terminal><Name>string</Name><Value>{&quot;0&quot;:&quot;First&quot;}</Value></Terminal></Response>


In fact, it looks a lot like XML (which I learned via a Google Search while writing this response).

In a previous thread, the solution you accepted mentions that for a LabVIEW Web Service you control, "you can change the response format to JSON".

If you follow the video instructions shown in the .gif file (called JSONOutputType.gif), it shows you how to change the output of your web service from XML to JSON.

 


@DeOdderKeith wrote:

And here is the LV2017 WEB Service that is supposed to respond with a String.

DeOdderKeith_1-1595911643358.png

It looks like you tried to produce the same result without using the instructions, since your indicator, "string", has proper JSON grammar.

 

 

Spoiler
Since that string came out of a "Flatten to JSON string" function, I would hope it would have proper JSON grammar...

But, what you did just outputs the JSON string as a literal string. It will then send out that string in XML format...which is what you are receiving, but in XML format...

 

 

Spoiler
...which NXG cannot handle, per the link that was in the solution you previously accepted.

Conclusion:

If you want it to output in a format that is readable by "Unflatten from JSON", please follow the well documented steps to change your Web Service output to JSON.

 

 

 

 

To give you a little more help, since I think you're outputting something you don't expect, let's parse that XML for you.

If you break it down to Start tags and End tags, it becomes

 

Spoiler
<Response>
    <Terminal>
        <Name>
            error out
        </Name>
        <Value>
            <Name>
                status
            </Name>
            <Value>
                0
            </Value>
            <Name>
                code
            </Name>
            <Value>
                0
            </Value>
            <Name>
                source
            </Name>
            <Value>
            </Value>
        </Value>
    </Terminal>
    <Terminal>
        <Name>
            string
        </Name>
        <Value>
            {&quot;0&quot;:&quot;First&quot;}
        </Value>
    </Terminal>
</Response>

 

 

Which, if we use our intuition, looks like this:

 

Spoiler
error out [cluster]
    status [boolean]
        0
    code [long]
        0
    source [string]
        "" (empty string)

string [string]
    {"0":"First"}


(using a mark-up language I just made up)

or, better yet, like this:

 

 

Spoiler
xml-parsed_JoB.PNG

(Using LabVIEW with NXG Style indicators. I don't have NXG, but I figure this is close enough.)

This, not coincidentally, matches the outputs of your Web Service exactly.

 

 

Spoiler
@DeOdderKeith wrote:

And here is the LV2017 WEB Service that is supposed to respond with a String.

DeOdderKeith_1-1595911643358.png


 

Conclusion:

If you don't want to send the "error out" cluster from your Web Service, don't create an "error out" indicator.

Maybe you want to send it, but from your description and code screenshots, I don't think you do.

Spoiler
An actual spoiler this time:
I have never used LabVIEW NXG nor LabVIEW Web Service, so please do not take what I say as good practice for either. Instead refer to real experts on these forums.

Please let the community know if this helped.

 

Regards,

joeorbob

 

P.S. If you haven't yet, you might look at this forum document. It uses LabVIEW instead of NXG, but seems like it has a lot of good information related to what you're doing.

Message 2 of 3
(2,605 Views)

Thanks so very much.

I guess as i get older it's getting harder to learn the first time and I have to be beat over the head.

 

That was it !!

 

 

KM

Message 3 of 3
(2,570 Views)