Liquid XML Data Binder (C++, Java, VB6) / Reference / Java / Reference / com.liquid_technologies.ltxmllib20 / XmlObjectBase / Java fromJson - JsonObjectInterface
In This Topic
    Java fromJson - JsonObjectInterface
    In This Topic
    void fromJson(String xmlIn)
                    throws LtException,
                               SAXException,
                               IOException;

    void fromJson( String xmlIn,
                           com.liquid_technologies.ltxmllib20.SerializationContext context)
                    throws LtException,
                               IOException;

      Property Description  
        Method Name fromJson  
        Argument - xmlIn A string containing the JSON to be loaded into the object.  
        Argument - context The SerializationContext 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.
    If this is not specified, the a default (SerializationContext.Default global static) instance of the class is used. If you are using several libraries generated from different schemas, or you want to change the way validation is performed for during the lifetime of the application or you are writing multithreaded code, then you should consider creating your own instance(s) of the SerializationContext.
    If you are writing a multithreaded app it is highly recommended that you use a different instance of this class on each thread, as access to the static instance is not synchronized. Although read only operations to the static instance (SerializationContext.Default) of the class are thread safe, if the global instance SerializationContext.Default is modified, then this could potentially cause threading problems.
     
        Description De-Serializes an JSON string into the current object.  
        Remarks

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

    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.

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/JSONSchema"
               elementFormDefault="qualified"
               attributeFormDefault="unqualified">
      <xs:element name="Person">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="name" type="xs:string"/>
            <xs:element name="Address">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="HouseNumber" type="xs:string"/>
                  <xs:element name="PostCode" type="xs:string"/>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>


    This would cause 2 classes to be generated Person & Address.
    So if you had the JSON Data.

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


    You would call FromJson on a Person object i.e.

    String strJSON = ... JSON data ...
    Person person = new Person();
    person.fromJson(strJSON)
    ;

    Character encoding.
    The default underlying parser supports the following character encodings

    • UTF-8
    • UTF-16
    • UNICODE

    Also See Multi-Language Support