0
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;
            }

        }

我希望方法“readIniData”返回 json 对象,而不是 json 字符串。

我尝试返回 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)

我的 CefSharp 版本是 79.1.360.0,这个版本是不是太低了?

4

1 回答 1

0

您可以为此使用 Json.Net。

JObject json = JObject.Parse(Contentjson);

于 2020-06-28T10:12:30.770 回答