[英]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.