其他分享
首页 > 其他分享> > json格式化与cefsharp简单使用

json格式化与cefsharp简单使用

作者:互联网

{
  "details": {
    "threeds2.fingerprint": "123"
  },
  "paymentData": "456"
}

jobj.SelectToken("details.['threeds2.fingerprint']")).Value<string>();

CefSettings settings = new CefSettings();
settings.Locale = "zh-CN";
settings.AcceptLanguageList = "zh-CN";
settings.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36";
Cef.Initialize(settings);

this.chromiumWebBrowser1.RequestHandler = new MyBasicRequestHandler();

this.chromiumWebBrowser1.Load("https://ditu.sossss.com/");

 



    public class MyCustomResourceRequestHandler : CefSharp.Handler.ResourceRequestHandler
    {
        private readonly System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();


        public delegate void MyInvoke(string str1);


        protected override IResponseFilter GetResourceResponseFilter(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IResponse response)
        {
            return new CefSharp.ResponseFilter.StreamResponseFilter(memoryStream);
        }

        protected override void OnResourceLoadComplete(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength)
        {
            //You can now get the data from the stream
            var bytes = memoryStream.ToArray();

            if (response.Charset == "utf-8")
            {
                var input = System.Text.Encoding.UTF8.GetString(bytes);
                if (input.IndexOf("bounds") == -1)
                {
                    return;
                }
                string pattern = @"\sjQuery\d+_\d+\(";
                string val1 = Regex.Replace(input, pattern, "").Replace("✱", "\"");
                val1 = val1.Substring(0, val1.LastIndexOf(");"));
                JObject joResponse = JObject.Parse(val1);

                var obj = joResponse.SelectToken("poi.['bounds']");
                if (obj == null)
                {
                    return;
                }
                SystemHandler.Instance.Bounds = joResponse["poi"]["bounds"].ToString();
                SystemHandler.Instance.Address = joResponse["poi"]["address"].ToString();
                SystemHandler.Instance.Adcode = joResponse["poi"]["adcode"].ToString();
                SystemHandler.Instance.Name = joResponse["poi"]["name"].ToString();
            }
            else
            {
                //Deal with different encoding here
            }
        }

        private void create_polygon(string bounds2)
        {
            IWorkspaceEdit pWspEdit = SystemHandler.Instance.Workspace as IWorkspaceEdit;
            pWspEdit.StartEditing(false);
            //pWspEdit.StartEditOperation();

            var bounds = "32.393310,119.410623;32.393336,119.411476;32.396008,119.411320;32.395951,119.410533;32.396208,119.410493;32.396047,119.408827;32.394279,119.409105;32.394361,119.409721;32.394212,119.409738;32.394324,119.410487;32.393310,119.410623";
            IPointCollection pointCollection = new MultipointClass();
            var pts = bounds.Split(';');
            for (int i = 0; i < pts.Length - 1; i++)
            {
                var arr = pts[i].Split(',');
                var x = Convert.ToDouble(arr[1]);
                var y = Convert.ToDouble(arr[0]);
                var pPoint = new ESRI.ArcGIS.Geometry.Point();
                pPoint.PutCoords(x, y);
                pointCollection.AddPoint(pPoint, Type.Missing, Type.Missing);
            }

            var poly = Utilities.CreatePolygonByPoints(pointCollection);
            ITopologicalOperator ptopo = poly as ITopologicalOperator;
            ptopo.Simplify();
            var fea = SystemHandler.Instance.CourtLayer.FeatureClass.CreateFeature();
            fea.Shape = poly;
            fea.set_Value(fea.Fields.FindField("Name"), "aaaa");
            fea.Store();

            //pWspEdit.StopEditOperation();
            pWspEdit.StopEditing(true);


            Utilities.PanTo(fea, SystemHandler.Instance.ActiveView);
            SystemHandler.Instance.ActiveView.Refresh();
            MessageBox.Show("OK");
        }
    }

    public class MyBasicRequestHandler : CefSharp.Handler.RequestHandler
    {
        protected override IResourceRequestHandler GetResourceRequestHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
        {
            //Only intercept specific Url's
            if (request.Url.Contains("restapi.map.so.com/newapi"))
            {
                return new MyCustomResourceRequestHandler();
            }
            //Default behaviour, url will be loaded normally.
            return null;
        }

    }
View Code

 

标签:cefsharp,格式化,fea,joResponse,SystemHandler,Instance,json,var,new
来源: https://www.cnblogs.com/yansc/p/13958144.html