﻿ C++ FromJsonStream - CXmlObjectBase
Liquid XML Data Binder 2020
Liquid XML Data Binder (C++, Java, VB6) / Reference / C++ / Reference / CXmlObjectBase / C++ FromJsonStream - CXmlObjectBase
In This Topic
    C++ FromJsonStream - CXmlObjectBase
    In This Topic
    void FromJsonStream(const LPBYTE lpData, DWORD dwLen)
    void FromJsonStream(const LPBYTE lpData, DWORD dwLen, const CSerialiaztionContext& context)
    void FromJsonStream(const CBinaryData& data)
    void FromJsonStream(const CBinaryData& data, const CSerialiaztionContext& context)
      Property Description  
        Method Name FromJsonStream  
        Argument - lpData A pointer to a buffer containing the JSON data be de-serialized. The data can be in any valid (and supported) encoding, UTF-8, UNICODE etc. This can be an Json document or Fast Infoset document and can be a compressed gzip or zlib file  
        Argument - dwLen The size of the data, this is the number of bytes pointed to by lpData  
        Argument - data The JSON data to be de-serialized (See CBinaryData for more information)  
        Argument - context

    The CSerializationContext object controls the way in which JSON is serialized/de-serialized. Its main role is to control the way in which validation is performed and which namespaces are output.


        Description De-Serializes an JSON file into the current object.  

    This method will only load JSON that complies with the XSD schema.
    It will raise an exception if the JSON is invalid.

    This method provides a way to treat your JSON as if it were binary, there are a number of gotchas when manipulating encoded (ie UTF-8) data, if you treat it to much like a string (especially attempting to convert it to UNICODE as if it where a n ASCII string) then you can damage it (see below & Multi-Language Support). This method simply allows you to treat it as a chunk of binary data, avoiding any potential encoding issues.

    The root element in the JSON held within lpszJSONIn must correspond to the class which this method is being called on. So you have a simple schema.

    <xs:schema xmlns:xs="http://www.w3.org/2001/JSONSchema"
      <xs:element name="Person">
            <xs:element name="Address">
                  <xs:element name="HouseNumber" type="xs:string"/>

    This would cause 2 classes to be generated CPerson & CAddress.
    So if you had the JSON file test.xml, which contained.

      "Person": {
        "name": "Joe Blogs",
        "Address": {
          "HouseNumber": "15",
          "PostCode": "LS5 9PQ"

    You would call FromJson on a CPerson object ie

    CPersonPtr spPerson = CPerson::CreateInstance();

    Character encoding.
    The underlying parser is expat version 1.95.6, as supports the following character encodings

    • UTF-8
    • UTF-16

    Note - If you are working with a UNICODE build and UTF-8 encoded data.
    This issue does not relate directly to our product, but has come up a number of times and is worth noting. UTF-8 (or other similar) encoded data should not be held in a UNICODE string. Attempting to convert a UTF-8 encoded string to UNICODE can damage the data (UTF-8 uses all the values 0-255 to encode the data, some of this range is not valid in UNICODE, so attempting the conversion results in '?' being substituted for invalid chars).
    If you are not familiar with char encoding's, and this is possibly going to be an issue, then we recommend that within your application you consider JSON data to be binary in nature, and use the FromJsonStream method.

    See Multi-Language Support and Global Functions for more information.