Пример #1
0
        private void DeserializeArray()
        {
            iesJSON j2;
            int pStatus;
            string c;
            // *** Create an array of objects.  Each can be a value(string,number,boolean,object,array,null)
            _jsonType="array";

            System.Collections.Generic.List<Object> v=new System.Collections.Generic.List<Object>();
            endpos=endpos+1; // *** IMPORTANT! Move past [ symbol
            pStatus=1;
            do {
            j2=null;
            findnext();

            // *** Check if we are past the end of the string
            if (endpos>_jsonString.Length) {
                StatusErr(-41,"Past end of string before we found the ] symbol as the end of the object @" + endpos + " (e-41)");
                _value=v;
                return;
            }

            switch (pStatus) {
                case 1:
                    // *** This should be a JSON item: object, array, string, boolean, number, or null
                    j2=new iesJSON();
                    j2.UseFlexJson=UseFlexJson;
                    j2.ALLOW_SINGLE_QUOTE_STRINGS=ALLOW_SINGLE_QUOTE_STRINGS;
                    j2.Deserialize(_jsonString,endpos,true);
                    if (j2.Status!=0) {
                      if (j2.Status==-11) {
                      	// *** This is actually legitimate.  All white space can indicate an empty array.  For example []
                        // *** Here we are lenient and also allow a missing item.
                        // *** For example [,  NOTE! In this case, the missing item does NOT count as an element of the array!
                        // *** if you want to skip an item legitimately, use NULL  For example [NULL,
                        pStatus=2;
                      } else {
                        StatusErr(-42,"Failed to find item in JSON array @" + endpos + " (e-42) [" + j2.StatusMessage + "]");
                      }
                    } else {
                        // *** For all cases: object, array, string, number, boolean, null - keep the entire JSON object.
                        j2.Parent=this;
                        v.Add(j2);
                        endpos=j2.endpos;
                        pStatus=2;
                    }
                    j2=null;
                    break;
                case 2:
                    c=substr(_jsonString,endpos,1);
                    if (c!="," && c!="]") {
                        StatusErr(-43,"Expected , symbol to separate value in JSON array @" + endpos + " (e-43)");
                    } else {
                        endpos=endpos+1;
                        // *** if we found ] then successful completion of deserializing the object
                        if (c=="]") { _value=v; return; }
                        pStatus=1;
                    }
                    break;
            } // End Select
            } while (_status==0); //Loop
            j2=null;
            _value=v;
        }
Пример #2
0
        private void DeserializeObject()
        {
            iesJSON j2; string Key=""; int pStatus;
            // *** Look for name:value pairs as a Dictionary object
            _jsonType="object";

            System.Collections.Generic.List<Object> v=new System.Collections.Generic.List<Object>();
            endpos=endpos+1; // *** IMPORTANT! Move past { symbol
            pStatus=1;

            do {
            j2=null;
            findnext();

            // *** Check if we are past the end of the string
            if (endpos>=_jsonString.Length) {
                StatusErr(-15,"Past end of string before we found the } symbol as the end of the object @" + endpos + " (e-15)");
                _value=v;
                return;
            }

            switch (pStatus) {
                case 1:
                    // *** Get KEY: This MUST be a string with the name of the parameter
                    j2=new iesJSON();
                    j2.UseFlexJson=UseFlexJson;
                    j2.ALLOW_SINGLE_QUOTE_STRINGS=ALLOW_SINGLE_QUOTE_STRINGS;
                    j2.Deserialize(_jsonString,endpos,true);
                    if (j2.Status!=0) {
                      if (j2.Status==-11) {
                        // *** This is actually legitimate.  All white space can indicate an empty object.  For example {}
                        // *** Here we are lenient and also allow a missing parameter.  For example {,
                        pStatus=4;
                      } else {
                        StatusErr(-18,"Failed to find parameter name in parameter:value pair @" + endpos + " (e-18) [" + j2.StatusMessage + "]");
                      }
                    } else {
                        if (j2.jsonType!="string") {
                            StatusErr(-19,"Parameter name in parameter:value pair must be a quoted string @" + endpos + " (-e19)");
                        } else {
                            Key=j2.ValueString;
                            endpos=j2.endpos;
                            pStatus=2;
                        }
                    }
                    break;
                case 2:
                    if (substr(_jsonString,endpos,1)!=":") {
                        StatusErr(-16,"Expected : symbol in parameter:value pair @" + endpos + " (e-16)");
                    } else {
                        endpos=endpos+1;
                        pStatus=3;
                    }
                    break;
                case 3:
                    j2=new iesJSON();
                    j2.UseFlexJson=UseFlexJson;
                    j2.ALLOW_SINGLE_QUOTE_STRINGS=ALLOW_SINGLE_QUOTE_STRINGS;
                    j2.Deserialize(_jsonString,endpos,true);
                    int newendpos=j2.endpos;
                    // Check for blank=null (return status -11 and _jsonType=null)
                    if ((j2.Status==-11) && (j2.jsonType=="null") && (_UseFlexJson==true)) {
                        // Note: j2.status=-11 indicates nothing was found where there should have been a value - for FLEX JSON this is legitimate.
                        j2=CreateItem(null);
                        }
                    if (j2.Status!=0) {
                        StatusErr(-21,"Failed to find value in parameter:value pair. @" + endpos + " (e-21) [" + j2.StatusMessage + "]");
                    } else {
                        // Note: Above, j2.status=-11 indicates nothing was found where there should have been a value - for FLEX JSON this is legitimate.
                        // *** For all cases: object, array, string, number, boolean, or null
                        j2.Parent=this;
                        j2._key=Key;
                        v.Add(j2);  // FUTURE: THIS IS WRONG!  WE MUST CHECK TO SEE IF THE KEY ALREADY EXISTS!
                        endpos=newendpos;
                        pStatus=4;
                    }
                    j2=null;
                    break;
                case 4:
                    string c;
                    c=substr(_jsonString,endpos,1);
                    if (c!="," && c!="}") {
                        StatusErr(-17,"Expected , symbol to separate value pairs @" + endpos + " (e-17)");
                    } else {
                        endpos=endpos+1;
                        // *** if we found } then successful completion of deserializing the object
                        if (c=="}") { _value=v; return; }
                        pStatus=1;
                    }
                    break;
            } //End Select
            } while (_status==0); // Do Loop
            j2=null;
            _value=v;
        }
Пример #3
0
        // *** splitstr()
        // *** Used to split a reference string such as "O\'Brien".23."color"
        // *** The above reference would get from a json object, the O'Brien parameter in an object, then lookup the 23rd record in the array,
        // *** and look up the "color" parameter in that object.  Although this split follows the conventions of a json string (for simplicity)
        // *** it should not start with a "[" symbol, and typically does not contain boolean, object, array, or null entries.
        //DEFAULT-PARAMETERS
        //public object splitstr(string strInput) { return splitstr(strInput, '.'); }
        //public object splitstr(string strInput, char Separator) {
        public System.Collections.Generic.List<Object> splitstr(string strInput, char Separator='.')
        {
            iesJSON j2; int pStatus; int ptr; string c; System.Collections.Generic.List<object> s;
            // *** Create an array of objects.  Each can be a value(string,number,boolean,object,array,null)
            // *** but typically should only be 'string' or 'number' for the internal use within GetObj() and GetStr()
            s=new System.Collections.Generic.List<Object>();
            ptr=0;
            pStatus=1;
            while (ptr<=strInput.Length) {
            j2=null;
            findnext(strInput,ptr);

            switch (pStatus) {
                case 1:
                    // *** This should be a JSON item: object, array, string, boolean, number, or null
                    j2=new iesJSON();
                    j2.UseFlexJson=UseFlexJson;
                    j2.ALLOW_SINGLE_QUOTE_STRINGS=ALLOW_SINGLE_QUOTE_STRINGS;
                    j2.Deserialize(strInput,ptr,true);
                    if (j2.Status==0) {
                      if ((j2.jsonType=="string") || (j2.jsonType=="number")) {
                        // *** For all cases: Object, Array, String, Number, Boolean, or null
                        s.Add(j2.Value);
                        ptr=j2.endpos;
                        pStatus=2;
                      } else { pStatus=3; } // ERROR
                    } else { pStatus=3; } //ERROR
                    break;
                case 2:
                    c=substr(strInput,ptr,1);
                    if (c==(Separator + "")) {
                        ptr=ptr+1;
                        pStatus=1;
                    } else { pStatus=3; } //ERROR
                    break;
            } // switch
            if (pStatus==3) { return null; } // *** Indicates an error in string format
            } //do
            j2=null;
            return s;
        }