private void InitConnection(bool rebuildSchema)
        {
            JsonDataSourceConnectionStringBuilder builder = new JsonDataSourceConnectionStringBuilder(ConnectionString);
            JsonBase obj      = null;
            string   jsonText = builder.Json.Trim();

            if (jsonText.Length > 0)
            {
                if (!(jsonText[0] == '{' || jsonText[0] == '['))
                {
                    using (WebClient client = new WebClient())
                    {
                        try
                        {
                            client.Encoding = Encoding.GetEncoding(builder.Encoding);
                        }
                        catch
                        {
                            client.Encoding = Encoding.UTF8;
                        }
                        jsonText = client.DownloadString(jsonText);
                    }
                }
                obj = JsonBase.FromString(jsonText) as JsonBase;
            }

            string schema = builder.JsonSchema;

            // have to update schema
            if (schema != jsonSchemaString || jsonSchema == null || String.IsNullOrEmpty(jsonSchemaString))
            {
                JsonSchema schemaObj = null;
                if (String.IsNullOrEmpty(schema) || rebuildSchema)
                {
                    if (obj != null)
                    {
                        schemaObj = JsonSchema.FromJson(obj);
                        JsonObject child = new JsonObject();
                        schemaObj.Save(child);
                        jsonSchemaString = child.ToString();
                    }
                }
                else
                {
                    schemaObj        = JsonSchema.Load(JsonBase.FromString(schema) as JsonObject);
                    jsonSchemaString = schema;
                }

                if (schemaObj == null)
                {
                    schemaObj      = new JsonSchema();
                    schemaObj.Type = "array";
                }

                if (schemaObj.Type != "array")
                {
                    JsonSchema parentSchema = new JsonSchema();
                    parentSchema.Items = schemaObj;
                    parentSchema.Type  = "array";
                    schemaObj          = parentSchema;
                }

                jsonSchema = schemaObj;
            }

            if (obj is JsonArray)
            {
                jsonInternal = obj as JsonArray;
            }
            else
            {
                JsonArray result = new JsonArray();
                if (obj != null)
                {
                    result.Add(obj);
                }
                jsonInternal = result;
            }
        }
        private void InitConnection(bool rebuildSchema)
        {
            JsonDataSourceConnectionStringBuilder builder = new JsonDataSourceConnectionStringBuilder(ConnectionString);
            JsonBase obj      = null;
            string   jsonText = builder.Json.Trim();

            if (jsonText.Length > 0)
            {
                if (!(jsonText[0] == '{' || jsonText[0] == '['))
                {
                    //using (WebClient client = new WebClient())
                    //{
                    //    try
                    //    {
                    //        client.Encoding = Encoding.GetEncoding(builder.Encoding);
                    //    }
                    //    catch
                    //    {
                    //        client.Encoding = Encoding.UTF8;
                    //    }
                    //    jsonText = client.DownloadString(jsonText);
                    //}

                    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(jsonText);

                    foreach (var header in builder.Headers)
                    {
                        req.Headers.Add(header.Key, header.Value);
                    }

                    using (var response = req.GetResponse() as HttpWebResponse)
                    {
                        var encoding = Encoding.GetEncoding(response.CharacterSet);

                        using (var responseStream = response.GetResponseStream())
                            using (var reader = new System.IO.StreamReader(responseStream, encoding))
                                jsonText = reader.ReadToEnd();
                    }
                }
                obj = JsonBase.FromString(jsonText) as JsonBase;
            }

            string schema = builder.JsonSchema;

            // have to update schema
            if (schema != jsonSchemaString || jsonSchema == null || String.IsNullOrEmpty(jsonSchemaString))
            {
                JsonSchema schemaObj = null;
                if (String.IsNullOrEmpty(schema) || rebuildSchema)
                {
                    if (obj != null)
                    {
                        schemaObj = JsonSchema.FromJson(obj);
                        JsonObject child = new JsonObject();
                        schemaObj.Save(child);
                        jsonSchemaString = child.ToString();
                    }
                }
                else
                {
                    schemaObj        = JsonSchema.Load(JsonBase.FromString(schema) as JsonObject);
                    jsonSchemaString = schema;
                }

                if (schemaObj == null)
                {
                    schemaObj      = new JsonSchema();
                    schemaObj.Type = "array";
                }

                if (schemaObj.Type != "array")
                {
                    JsonSchema parentSchema = new JsonSchema();
                    parentSchema.Items = schemaObj;
                    parentSchema.Type  = "array";
                    schemaObj          = parentSchema;
                }

                jsonSchema = schemaObj;
            }

            if (obj is JsonArray)
            {
                jsonInternal = obj as JsonArray;
            }
            else
            {
                JsonArray result = new JsonArray();
                if (obj != null)
                {
                    result.Add(obj);
                }
                jsonInternal = result;
            }
        }