简体   繁体   English

cefsharp ChromiumWebBrowser,我如何将 json object 返回到 javascript,而不是字符串

[英]cefsharp ChromiumWebBrowser,how can i return json object to javascript,not string

browser.JavascriptObjectRepository.Register("BrowerFunc", new BrowerFunc(), isAsync: false, options: bo);
 public class BrowerFunc
        {
            public string readIniData(string Section, string iniFilePath) {
                string Contentjson = JsonConvert.SerializeObject(OperateIniFile.ReadIniDataAll(Section, iniFilePath));
                return Contentjson;
            }

        }

I want the method 'readIniData' return json object,not json string.我想要方法“readIniData”返回 json object,而不是 json 字符串。

I tried return Dictionary<string,object>,but throw some exceptions:我尝试返回 Dictionary<string,object>,但抛出一些异常:

Uncaught Error: System.ServiceModel.CommunicationException: 读取管道时出错: 管道已结束。 (109, 0x6d)。 ---> System.IO.PipeException: 读取管道时出错: 管道已结束。 (109, 0x6d)。
   在 System.ServiceModel.Channels.PipeConnection.FinishSyncRead(Boolean traceExceptionsAsErrors)
   在 System.ServiceModel.Channels.PipeConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
   --- 内部异常堆栈跟踪的结尾 ---

Server stack trace: 
   在 System.ServiceModel.Channels.PipeConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
   在 System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
   在 System.ServiceModel.Channels.SessionConnectionReader.Receive(TimeSpan timeout)
   在 System.ServiceModel.Channels.SynchronizedMessageSource.Receive(TimeSpan timeout)
   在 System.ServiceModel.Channels.TransportDuplexSessionChannel.Receive(TimeSpan timeout)
   在 System.ServiceModel.Channels.TransportDuplexSessionChannel.TryReceive(TimeSpan timeout, Message& message)
   在 System.ServiceModel.Dispatcher.DuplexChannelBinder.Request(Message message, TimeSpan timeout)
   在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   在 CefSharp.Internals.IBrowserProcess.CallMethod(Int64 objectId, String name, Object[] parameters)
   在 CefSharp.JavascriptMethodWrapper.Execute(Object[] parameters) 位置 c:\projects\cefsharp\cefsharp.browsersubprocess.core\javascriptmethodwrapper.cpp:行号 24
   在 CefSharp.JavascriptMethodHandler.Execute(JavascriptMethodHandler* , CefStringBase<CefStringTraitsUTF16>* name, scoped_refptr<CefV8Value>* object, vector<scoped_refptr<CefV8Value>\,std::allocator<scoped_refptr<CefV8Value> > >* arguments, scoped_refptr<CefV8Value>* retval, CefStringBase<CefStringTraitsUTF16>* exception) 位置 c:\projects\cefsharp\cefsharp.browsersubprocess.core\javascriptmethodhandler.cpp:行号 15
    at ICCInter_HZFun (test.html:16)
    at HTMLButtonElement.onclick (test.html:8)

My CefSharp version is 79.1.360.0,is this version too low?我的 CefSharp 版本是 79.1.360.0,这个版本是不是太低了?

You can use Json.Net for this.您可以为此使用 Json.Net。

JObject json = JObject.Parse(Contentjson) ; JObject json = JObject.Parse(Contentjson) ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将此 json object 返回到字符串中 - How can I return this json object into a string 如何使用jquery或javascript从对象内部将当前对象作为JSON字符串返回? - How can I return the current object as a JSON string from inside the object with jquery or javascript? CefSharp ChromiumWebBrowser javascript excel 导出不起作用 - CefSharp ChromiumWebBrowser javascript excel export not working 如何将JSON字符串转换为JavaScript Object Literal - How can I convert my JSON string to a JavaScript Object Literal 如何在javascript中返回带有对象的字符串? - How do I return a string with an object in javascript? 我如何返回JSON对象属性 - How can i return a JSON object property Javascript:如何返回 object 类型? - Javascript : How can i return object type? 如何将 VB.net 代码中定义的字符串变量的值传递到 CefSharp 浏览器中,并使用 Javascript 按名称调用它们? - How can I pass the values of string variables defined in VB.net code into a CefSharp browser and call them by their name using Javascript? 在JavaScript中,如何返回一个布尔值,指示一个键是否存在于JSON对象中? - In JavaScript, how can I return a boolean value indicating whether a key is present in a JSON object? 如何在 Javascript 中返回 JSON object? - How to return JSON object in Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM