首页 \ 问答 \ 从JSONObject获取Vector对象(Get Vector object from JSONObject)

从JSONObject获取Vector对象(Get Vector object from JSONObject)

我想知道是否有办法从JSONObject中获取Vector。 假设我有这个:

public class Foo
    private JSONObject json;
    public Foo(){
        try{ 
            json=new JSONObject();
            Vector<,F> v=new Vector<,F>(); // pretend like the comma isn't there please 
            json.put("blah", v); ...} catch (JSONException e){...}
    } 
    .
    .
    .
    public void addBlahs(,F goo){
         try{
            Object o=json.get("blah");
            // Since json.get("blah") should be a Vector of .F's, I thought I could do something like this...
            Vector<,F> v=(Vector <,F>) o;
            v.add(goo);} catch (JSONException{ ...}
    }

Eclipse给出了一个警告,说明未经检查的类型转换。 是否可以从JSONObject获取某种类型的对象,然后能够使用该对象? 我想在该Vector中添加“goo”,但不确定如何正确访问它并添加到它。

我是初学者,所以对我很轻松:)


I am wondering if there is a way to get a Vector from out of a JSONObject. Let's say I have this :

public class Foo
    private JSONObject json;
    public Foo(){
        try{ 
            json=new JSONObject();
            Vector<,F> v=new Vector<,F>(); // pretend like the comma isn't there please 
            json.put("blah", v); ...} catch (JSONException e){...}
    } 
    .
    .
    .
    public void addBlahs(,F goo){
         try{
            Object o=json.get("blah");
            // Since json.get("blah") should be a Vector of .F's, I thought I could do something like this...
            Vector<,F> v=(Vector <,F>) o;
            v.add(goo);} catch (JSONException{ ...}
    }

Eclipse gives me a warning saying unchecked type cast. Is it possible to get a certain type of object from a JSONObject and then be able to use that object? I want to add "goo"s to that Vector, but not sure how to properly access it and add to it.

I'm a beginner so go easy on me :)


原文:https://stackoverflow.com/questions/12608472
更新时间:2023-05-11 06:05

最满意答案

看起来如果没有visual studio的自定义插件,就不可能在车把模板中获得语法高亮。


It looks like that without custom plugin for visual studio it is not possible to get syntax highlight inside handlebar template.

相关问答

更多
  • 您需要指定允许在中间模板中通过的部分。 BaseTemplate.cshtml @ViewBag.Title @RenderSection("HeaderContent", false) @* The region of the header scripts (custom css) *@ @RenderBody() 编辑 你的 ...
  • 好吧,你可能认为这更容易阅读和维护,但事实并非如此。 您不想打开javascript文件来编辑模板/标记; 就像你不想打开CSS来调试Javascript(记得expression() ?)。 我们的想法是通过您的构建系统预编译您的模板。 如果您通过requireJs加载器插件加载模板,这可能很容易; 例如: template: require("hbs!templates/listItem") 您还可以查看Backbone Boilerplate现在如何做到这一点: https : //github.c ...
  • 您可以使用http://razorengine.codeplex.com/实现此目的。 它允许您使用mvc外的剃刀。 string Email = "Hello @Model.Name! Welcome to Razor!"; string EmailBody = Razor.Parse(Email, new { Name = "World" }); 它很容易实现,它可以在http://nuget.codeplex.com/上找到 ,方便您的项目集成。 You can use http://razoren ...
  • Razor允许您以后制作更复杂的电子邮件,而无需完全重新设计您的电子邮件系统。 例如,您可以包含条件。 Razor allows you to make more complicated emails later without needing to completely redesign your email system. For example, you can include conditionals.
  • 使用@model标记实际上是@inherits标记的快捷方式。 您指定了类,您生成的类将继承自使用@inherits指定的类。 因此,如果您指定@inherits MyTemplate MyTemplate应如下所示: class MyTemplate { public T Model { get; set; } public abstract void Execute(); public virtual void Write(object value) { ...
  • 我们不能做自定义分隔符(Handlebars的缺点),但有几个解决方案可能适合您。 这两者都不一定是惯用的,所以你要判断这些对你正在进行的项目来说是多么合适。 字符串替换 你可以使用一些自定义(临时)分隔符来处理内容中不应该被编译的模板,然后创建一个块帮助程序,在编译期间将这些分隔符转换回有效的句柄表达式(我测试了这个答案并且它可以工作): 例如: Handlebars.registerHelper("raw", function(options) { return options.fn(this).r ...
  • 如果您想要多个文件,请像这样在命令中列出它们 handlebars file1 file2 file3 -f outfile 您希望为您的生产站点存储预编译的文件,因为它大大缩短了加载时间。 If you want multiple files, list them in the command like so handlebars file1 file2 file3 -f outfile You DO want to store precompiled files for your productio ...
  • 尝试使用Ember.keys : Ember.keys(Ember.TEMPLATES); 希望能帮助到你。 Try using Ember.keys: Ember.keys(Ember.TEMPLATES); Hope it helps.
  • 看起来如果没有visual studio的自定义插件,就不可能在车把模板中获得语法高亮。 It looks like that without custom plugin for visual studio it is not possible to get syntax highlight inside handlebar template.
  • 在此上下文中进行编译意味着将模板字符串转换为Javascript函数。 对于您的示例,生成的函数体将类似于return '' + title + '' 。 这比使用正则表达式处理模板更快。 这也意味着编译后的模板可以在浏览器中使用,而不需要整个Handlebars库。 Compiling in this context means converting your template string into a Javascript function. For your example t ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。