我正在从客户端Web应用程序发送一个Json数组到asp.net webapi.例如,
{
"SurveyId":3423,
"CreatorId":4235,
"GlobalAppId":34,
"AssociateList":[
{"AssociateId":4234},
{"AssociateId":43},
{"AssociateId":23423},
{"AssociateId":432}
],
"IsModelDirty":false,
"SaveMode":null
}
Run Code Online (Sandbox Code Playgroud)
这里的Associate List是一个JSON数组,通常它会自动序列化为List <>对象.
使用下面的代码,我将响应发布到WebApi
public IEnumerable<Associate> Post(ResponseStatus responseStatus)
{
return this.responsestatusrepository.ResponseStatusCheck(responseStatus);
}
Run Code Online (Sandbox Code Playgroud)
ResponseStatus类如下所示.
public class ResponseStatus : AppBaseModel
{
public int SurveyId { get; set; }
public int CreatorId { get; set; }
public int GlobalAppId { get; set; }
public List<Associate> AssociateList { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我已将List <>更改为Collection <>,作为我的代码分析更正的一部分.即public Collection<Associate> AssociateList { get; set; }
但是当我们使用集合而不是List时,它总是得到一个空值.这有什么具体原因吗?
我正在开发一个小型游戏模板,其中包含如下节点的世界:
World
|--Zone
|----Cell
|------Actor
|------Actor
|--------Item
Run Code Online (Sandbox Code Playgroud)
如果a World
可以包含多个Zone
对象,则a Zone
可以包含多个Cell
对象,依此类推.
所有这些实现的Node
接口,它有一些方法,如getParent
,getChildren
,update
,reset
等.
我希望能够Task
在单个节点上执行给定,或者从节点(由指定的Task
)指定的树上递归执行.
为了解决这个问题,我希望这是一个"可插拔"系统,这意味着我希望玩家/开发人员能够动态地向树中添加新类型.我还考虑过基类型的转换:
public void doTask(Actor node)
{
if(!(node instanceof Goblin)) { return; }
Goblin goblin = (Goblin) node;
}
Run Code Online (Sandbox Code Playgroud)
最初我被吸引使用访客模式来利用双重调度,允许每个例程(访问者)根据Node
被访问的类型行事.但是,这会引起一些复杂情况,特别是当我想Node
在树中添加新类型时.
作为替代方案,我编写了一个实用类,它使用反射来查找适用于该方法的最具体方法Node
.
我现在关心的是表现 ; 因为会有相当多的反思查找和调用,我担心我的游戏性能(每秒可能有数百或数千个这样的调用)会受到影响.
这似乎解决了这两种模式的问题,但却使每个新的代码Task
更加丑陋.
我看到它的方式,我有三个允许这种动态调度的选项(除非我遗漏了明显/模糊的东西,这就是为什么我在这里):
Node
类型(不修改原始代码就不可能)我注意到实现动态数组非常常见(特别是在面试问题和家庭作业中); 通常,我看到的问题是:
实现一个阵列,当满了时容量翻倍
或者非常相似的东西.他们几乎总是(根据我的经验)明确地使用双词,而不是更一般
实现一个阵列,在满员时增加容量
我的问题是,为什么加倍?我理解为什么使用常量值是个坏主意(感谢这个问题),但似乎使用更大的倍数而不是双倍更有意义; 为什么不将容量增加三倍,或者将容量增加四倍,或者将其平方?
要清楚,我不是要问如何将数组的容量加倍,我问为什么加倍是常规.
我正在尝试使用Google serviceGenerator
以发现文档作为输入从Google后端生成客户端API代码.以下是确切的命令:
/Users/raja/Library/Developer/Xcode/DerivedData/ServiceGenerator-dycdiotwolfqnaelznaucewpppjr/Build/Products/Debug/ServiceGenerator ./userRecordApi-v1-rpc.discovery --outputDir ~/API
Run Code Online (Sandbox Code Playgroud)
但是,我看到以下错误
dyld: Symbol not found: ___NSDictionary0__
Referenced from: /Users/raja/Library/Developer/Xcode/DerivedData/ServiceGenerator-dycdiotwolfqnaelznaucewpppjr/Build/Products/Debug/ServiceGenerator (which was built for Mac OS X 10.11)
Expected in: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
in /Users/raja/Library/Developer/Xcode/DerivedData/ServiceGenerator-dycdiotwolfqnaelznaucewpppjr/Build/Products/Debug/ServiceGenerator
Trace/BPT trap: 5
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
谢谢,拉贾.
arrays ×1
collections ×1
ios ×1
ios9 ×1
java ×1
json ×1
list ×1
objective-c ×1
reflection ×1
visitor ×1
xcode7 ×1