我试图将数据从我的JSON文件传递到一个简单的ViewController标签,但我不知道在哪里实际传递该数据.我能够只添加到我的setDataToJson方法中,还是会在我的viewDidLoad方法中添加数据?
这是我的代码
@interface NSDictionary(JSONCategories)
+(NSDictionary*)dictionaryWithContentsOfJSONString:(NSString*)fileLocation;
@end
@implementation NSDictionary(JSONCategories)
+(NSDictionary*)dictionaryWithContentsOfJSONString:(NSString*)fileLocation{
NSData* data = [NSData dataWithContentsOfFile:fileLocation];
__autoreleasing NSError* error = nil;
id result = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions error:&error];
if (error != nil) return nil;
return result;
}
@end
@implementation ViewController
@synthesize name;
- (void)viewDidLoad
{
[super viewDidLoad];
}
-(void)setDataToJson{
NSDictionary *infomation = [NSDictionary dictionaryWithContentsOfJSONString:@"Test.json"];
name.text = [infomation objectForKey:@"AnimalName"];//does not pass data
}
Run Code Online (Sandbox Code Playgroud) 所以android.view.ViewGroup当我尝试在图形视图中查看我的xml时,我没有看到它在哪里投入到我收到此错误消息.我还没有对这个实际的java做任何事情.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffffff"
android:orientation="vertical" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:stretchColumns="1" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="1.0dp"
android:background="@drawable/list_divider_holo_light" />
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
Run Code Online (Sandbox Code Playgroud)
在这里,我厌倦了用这些元素制作一种风格,它不会接受它.
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="25dp"
android:text="@string/add_alarm"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ff505050"
android:textSize="18.0sp" />
<Button
android:id="@+id/bSetTimer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="100.0dp"
android:text="Button" />
</TableRow>
<Button
android:id="@+id/bSetAlarm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Small Text" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="2.0dp"
android:background="@drawable/list_divider_holo_light" />
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp" >
<TextView
android:layout_height="20.0dp"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="40.0dp"
android:paddingLeft="25.0dip"
android:text="@string/alarm_volume_title" />
</TableRow>
<SeekBar
android:id="@+id/default_volume_seekbar"
android:layout_width="fill_parent" …Run Code Online (Sandbox Code Playgroud) 我正在将我的 MVC 项目迁移到 Core,并且我一直很难修复所有旧的 ajax 调用。
我可以将模型和字符串参数传递给控制器,但是,整数对我不起作用。
我可以将它们作为字符串参数包装到 JSON 对象中,例如[FromBody]string objId在控制器中,但随后我必须从 Json 解析 int val {'objId' : 1}。
有没有办法可以避免这种情况而只传递一个整数?
下面是我正在尝试的代码。
[HttpPost]
public JsonResult PassIntFromView([FromBody]int objId)
{
//DO stuff with int here
}
Run Code Online (Sandbox Code Playgroud)
这是js。
var data = { "objId": 1};
$.ajax({
url: '@Url.Action("PassIntFromView", "ControllerName")',
data: JSON.stringify(data),
type: "POST",
dataType: 'JSON',
contentType: "application/json",
success: function(data) {
//do stuff with json result
},
error: function(passParams) {
console.log("Error is " + passParams);
}
});
Run Code Online (Sandbox Code Playgroud)
的objId是在控制器中始终为0。
我试过这个,但没有做JSON.stringify(data)也没有结果。
我还尝试了所有不同的表单属性变体。
所以我正在查看 google 的操作栏 api 演示,他们有这个
// The Action Bar is a window feature. The feature must be requested
// before setting a content view. Normally this is set automatically
// by your Activity's theme in your manifest. The provided system
// theme Theme.WithActionBar enables this for you. Use it as you would
// use Theme.NoTitleBar. You can add an Action Bar to your own themes
// by adding the element <item name="android:windowActionBar">true</item>
// to your style definition.
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
Run Code Online (Sandbox Code Playgroud)
但是当我尝试添加最后一行代码时,getWindow().requestFeature(Window.FEATURE_ACTION_BAR); …