cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

How to convert JSON file to a WSTRING?

How to convert JSON file to a WSTRING?

mdirzpr_13
New Poster

I want to use WebClient Function Block from Web_Client_SL library in IIOT to PUT an APPLICATION_JSON. For this goal I need to define the PostValue as a WSTRING and then define a Pointer for it to give the pointer as an input to FB. The first problem which I have is that when I give a json file to a WSTRING variable, the compiler returns an error. So what is the proper way to assign this json string in a variable?

For solving this problem, I used the JSON_Utilities_SL library in IIOT to convert a JSON file to a WSTRING. With JSONFileReader FB, I can make a JSONData object. How we can convert this JSONData object to WSTRING?

There is a function called JSONElementToString. For implementing it we need to extract the JSON elements. So I used the GetElementByIndex method to get the JSON elements. But the problem is that, I do not know the number of indexes for an arbitrary JSON file. What should I do?

4 REPLIES 4

CodeShepherd
Community Moderator
Community Moderator

I guess you are using a CODESYS based library so I moved this topic to the CODESYS - PLC Add-ons forum.

Yes, I am using IIOT library. Thank you.

HmiGuide
Community Moderator
Community Moderator

I'm not sure, if I understand your description correct. I see  2 differnet use cases:

A: Pass the JSON file content, without changing anything

  1. Open file, Read content STRING/WSTRING, Close file
  2. Send WSTRING via Web_Client_SL library

B: Pass the JSON file content, with changing it

  1. Open file, Read content STRING/WSTRING, Close file
  2. Parse string into JSON object
  3. Edit JSON object
  4. Create WSTRING from JSON object
  5. Send WSTRING via Web_Client_SL library

Remarks:

  • When you do not have to change the content of the JSON object, you do not need the JSON library of CoDeSys.
  • Just use the library CXA_FileAsync. It's a wrapper around the CoDeSys function, which are really hard to use.
  • If the file format is STRING, you have to read it as STRING and convert it afterwards to WSTRING
  • If the file format is WSTRING, you have to read it as WSTRING
  • In my tests around 1 year ago, the CoDeSys JSON library was not very stable. I would use it only for very basic stuff but not for complex JSON's.

georkueh
Community Moderator
Community Moderator

Hello,

has your problem been solved in the meantime?

kind regards

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist