我使用RestSharp访问Rest API.我喜欢将数据作为POCO返回.我的RestSharp客户端看起来像这样:
var client = new RestClient(@"http:\\localhost:8080");
var request = new RestRequest("todos/{id}", Method.GET);
request.AddUrlSegment("id", "4");
//request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };
//With enabling the next line I get an new empty object of TODO
//as Data
//client.AddHandler("*", new JsonDeserializer());
IRestResponse<ToDo> response2 = client.Execute<ToDo>(request);
ToDo td=new JsonDeserializer().Deserialize<ToDo>(response2);
var name = response2.Data.name;
Run Code Online (Sandbox Code Playgroud)
我的JsonObject类看起来像这样:
public class ToDo
{
public int id;
public string created_at;
public string updated_at;
public string name;
}
Run Code Online (Sandbox Code Playgroud)
和Json的回应:
{
"id":4,
"created_at":"2015-06-18 09:43:15",
"updated_at":"2015-06-18 09:43:15",
"name":"Another Random …
Run Code Online (Sandbox Code Playgroud) 我喜欢使用Selenium chromewebdriver来测试应用程序.
我从这个教程开始:https://code.google.com/p/selenium/wiki/WebDriverJs#Getting_Started
我下载了最新版webdriver
并将其添加到路径中,然后我尝试执行您在开始时看到的示例代码.我将代码添加到脚本并尝试执行它> node script.js
并收到以下错误消息:
undefined:1178
vlog(2, () => this + ' scheduling notifications', this);
^
SyntaxError: Unexpected token )
at goog.loadModuleFromSource_ (C:\nodescripts\node_modules\selenium-webdriver\lib\goog\base.js:1123:19)
at Object.goog.loadModule (C:\nodescripts\node_modules\selenium-webdriver\lib\goog\base.js:1085:46)
at C:\nodescripts\node_modules\selenium-webdriver\lib\webdriver\promise.js:1:6
at Object.exports.runInContext (vm.js:64:17)
at Object.Context.closure.goog.retrieveAndExecModule_ (C:\nodescripts\node_modules\selenium-webdriver\_base.js:135:8)
at <anonymous>:1:6
at Object.exports.runInContext (vm.js:64:17)
at Context.closure.closure.vm.createContext.CLOSURE_IMPORT_SCRIPT (C:\nodescripts\node_modules\selenium-webdriver\_base.js:104:12)
at Object.goog.importScript_ (C:\nodescripts\node_modules\selenium-webdriver\lib\goog\base.js:879:9)
at Object.goog.importModule_ (C:\nodescripts\node_modules\selenium-webdriver\lib\goog\base.js:900:14)
Run Code Online (Sandbox Code Playgroud) 我正在使用Serverfireteam LaravelPanel(使用zofe/rapyd-laravel).我为一个实体创建了一个crud控制器.此实体具有另一个表的外键.现在我想显示这个外键的自动完成,但它只显示一个空的选择框.
我的Controller代码如下所示:
public function edit($entity){
parent::edit($entity);
$this->edit = \DataEdit::source(new \App\Regal());
$this->edit->add('bezeichnung', 'Bezeichnung','text');
$this->edit->add('nummer', 'Nummer','text');
$this->edit->add('maxPaletten', 'Max Paletten je Ebene','text');
$this->edit->add('anzahlEbenen', 'Anzahl Ebenen','text');
$this->edit->add('kunde_id','Kunde','select')->options(\App\Kunde::lists("name", "id"));
return \View::make('regale.editPanel', array(
'title' => $this->entity ,
'edit' => $this->edit
));
}
Run Code Online (Sandbox Code Playgroud)
我的模型文件:
class Kunde extends Model {
protected $table = 'kunden';
public function listPaletten(){
return $this->hasMany('App\Models\Palette');
}
public function listAdressen(){
return $this->hasMany('App\Models\Adresse');
}
public function listRegale(){
return $this->hasMany('App\Models\Regal');
}
public function listArtikel(){
return $this->hasMany('App\Models\Artikel');
}
}
Run Code Online (Sandbox Code Playgroud)
..
class Regal extends Model {
protected $table …
Run Code Online (Sandbox Code Playgroud) 我使用 Laravel,我在 App/Models 下有一个 Model 类
<?php
namespace App\Models;
class TodoList extends \Eloquent{
public function listItems(){
return $this->hasMany('TodoItem');
}
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我包含了命名空间,如下所示:
namespace App\Http\Controllers;
...
use App\Models\TodoItem;
use App\Models\TodoList;
class TodoListController extends Controller
Run Code Online (Sandbox Code Playgroud)
我的方法如下所示:
public function show($id)
{
$list=TodoList::findOrFail($id);
return \View::make('todos.show')->with('list', $todo_list);
}
Run Code Online (Sandbox Code Playgroud)
但是当我调用请求时,我收到错误:
TodoListController.php 第 75 行中的 FatalErrorException:未找到类“App\Models\TodoList”
我想CommonServiceLocator.MefAdapter
在我的Visual Studio Community 2015项目中加入.当我尝试安装软件包时:https://www.nuget.org/packages/CommonServiceLocator.MefAdapter/1.0.0
我收到错误:
PM> Install-Package CommonServiceLocator.MefAdapter Install-Package:无法找到包'CommonServiceLocator.MefAdapter'在行:1 char:17 + Install-Package <<<< CommonServiceLocator.MefAdapter + CategoryInfo:NotSpecified:(:) [Install-包],Exception + FullyQualifiedErrorId:NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
我找到了一个Propperty Changed Event的实现,我可以在没有Web中属性名称的情况下更改Call Property.然后我在这里建立了一个扩展方法
public static void OnPropertyChanged(this INotifyPropertyChanged iNotifyPropertyChanged, string propertyName = null)
{
if (propertyName == null)
propertyName = new StackTrace().GetFrame(1).GetMethod().Name.Replace("set_", "");
FieldInfo field = iNotifyPropertyChanged.GetType().GetField("PropertyChanged", BindingFlags.Instance | BindingFlags.NonPublic);
if (field == (FieldInfo) null)
return;
object obj = field.GetValue((object) iNotifyPropertyChanged);
if (obj == null)
return;
obj.GetType().GetMethod("Invoke").Invoke(obj, new object[2]
{
(object) iNotifyPropertyChanged,
(object) new PropertyChangedEventArgs(propertyName)
});
}
Run Code Online (Sandbox Code Playgroud)
所以我可以将Property更改为:
private bool _foo;
public bool Foo
{
get { _foo; }
private set
{
_foo = value;
this.OnPropertyChanged();
}
}
Run Code Online (Sandbox Code Playgroud)
但我想,如果我在使用Property更改时不必实现属性的getter和setter,那就更好了. …