首页 \ 问答 \ 在JavaScript中获取json对象的键[duplicate](get keys of json-object in JavaScript [duplicate])

在JavaScript中获取json对象的键[duplicate](get keys of json-object in JavaScript [duplicate])

这个问题已经在这里有一个答案:

  • 获取JavaScript对象密钥列表 11的答案

我在JavaScript中有一个json对象,我想在其中获取使用的键。 我的JavaScript代码如下所示:

var jsonData = [{"person":"me","age":"30"},{"person":"you","age":"25"}];

我想要一个循环,提醒我的“人”和“年龄”,这是json-Array中第一个对象的关键。


This question already has an answer here:

I have a json-object in JavaScript and I want to get the used keys in it. My JavaScript-Code looks like this:

var jsonData = [{"person":"me","age":"30"},{"person":"you","age":"25"}];

And I want a loop that alerts me 'person' and 'age', which are the keys of the first object in the json-Array.


原文:https://stackoverflow.com/questions/8430336
更新时间:2023-06-13 15:06

最满意答案

正如我所评论的,我写这个答案可能会帮助某人。这段代码只会在X轴上移动视图

@Override
public boolean onTouch(View v, MotionEvent event) {

    switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            dX = v.getX() - event.getRawX();
            dY = v.getY() - event.getRawY();
            lastAction = MotionEvent.ACTION_DOWN;
            break;

        case MotionEvent.ACTION_MOVE:
           //remove this v.setY() line
            v.setX(event.getRawX() + dX);
            lastAction = MotionEvent.ACTION_MOVE;
            break;

        case MotionEvent.ACTION_UP:
            if (lastAction == MotionEvent.ACTION_DOWN)
                Toast.makeText(MainActivity.this, "Clicked!", Toast.LENGTH_SHORT).show();
            break;

        default:
            return false;
    }
    return true;
}

Finally this problem is resolved by making some changes in my code.Hope this will help someone achieving this effect.

@Override
public boolean onTouch(View v, MotionEvent event) {

    switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            dx = v.getX() - event.getRawX();
            dy = v.getY() - event.getRawY();
            ball_dx = ball.getX();
            lastAction = MotionEvent.ACTION_DOWN;
            break;

        case MotionEvent.ACTION_MOVE:
            //  ball.setY(event.getRawY() + dy);
            if ((event.getRawX() + dx + ball_dx) < screenwidth - 80 && (event.getRawX() + dx + ball_dx) > 10)
                ball.setX(event.getRawX() + dx + ball_dx);
            lastAction = MotionEvent.ACTION_MOVE;
            break;

        case MotionEvent.ACTION_UP:
            if (lastAction == MotionEvent.ACTION_DOWN)
                Toast.makeText(MainActivity.this, "Clicked!", Toast.LENGTH_SHORT).show();
            break;
        default:
            return false;
    }
    return true;
}

相关问答

更多
  • 问题是你的线性冲动很强。 您可以使用Mario项目对此进行测试,如果增加冲动,您也会陷入墙壁。 要解决这个问题,要么降低冲量,降低摩擦力(但是你可能需要停止马里奥的代码)或者不是应用线性冲动,而是应用火炬并使用圆形形状让玩家“滚动”。 这些解决方案都不是完美的,但您可以尝试看看哪一种最适合您。 The problem is that your linear impulse is to strong. You can test this with the Mario project, if you incre ...
  • 正如我所评论的,我写这个答案可能会帮助某人。这段代码只会在X轴上移动视图 @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: dX = v.getX() - event.getRawX(); dY = v.getY() - event. ...
  • override func touchesMoved(touches: Set, withEvent event: UIEvent?){ let touch = touches.anyObject() as UITouch! let touchLocation = touch.locationInNode(self) let previousLocation = touch.previousLocationInNode(self) ...
  • 好的,这是现在正在工作,但我相信我会有另外一个问题。 当我在上面运行时,我创建了一个相当小的动态盒子,这样物品就堆积在地上,相互重叠。 dynamicBox.SetAsBox(.25f,.25f) 这是原因。 当我把它打开到更大的东西时,说: dynamicBox.SetAsBox((spriteSize.width / PTM_RATIO)/ 4,(spriteSize.height / PTM_RATIO)/ 4); 然后,通过上述代码可以触摸身体。 (所以我的问题需要重新制定,因为我确实希望物体堆积起 ...
  • 您可能会收到该错误,因为您无法从树中的任何节点访问该视图。 您可以将其称为场景!.view或您在场景中处理手势,如果您想要保持简单,这是更可取的。 我试了一下,想出了这个基本场景: import SpriteKit class GameScene: SKScene { var shape:SKNode! override func didMoveToView(view: SKView) { //creates the shape to be moved ...
  • 因此,您希望用户能够沿着弯曲路径在关键帧动画的中间触摸图像,并将其拖动到其他位置? 那时你想要发生什么动画? 你有多重挑战。 首先是在关键帧动画处于“飞行中”时检测对象上的触摸。 要做到这一点,你想使用父视图的图层的表示层的hitTest方法。 一个图层的表示层表示在任何给定时刻图层的状态,包括动画。 一旦检测到视图上的触摸,就需要从表示层获取图像的当前位置,停止动画,然后接管基于touchesMoved / touchesDragged的动画。 我写了一个演示应用程序,演示如何检测沿着路径动画的对象的触摸 ...
  • 为此,您需要将taoGesture与UISlider一起使用,因此首先在滑块对象中添加UITapGestureRecognizer ,然后在gestureRecognizer选择器的action方法中设置其值。 在视图中添加滑块后添加以下代码。 UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSliderTap:)]; [ ...
  • 为什么不在onTouchEvent回调中获取并存储先前的MotionEvent坐标,然后当onTouchEvent再次触发时(ACTION_DOWN之后的第一个ACTION_MOVE,然后为每个ACTION_MOVE回调再触发)计算出值之间的偏移/差异,然后得到你自己的myPoint坐标并添加对当前值的偏移量。 这样你只能通过位置偏移来移动myPoint对象,而不是实际的坐标。 此代码未经过测试,我没有使用IDE,但是这样: private float oldX; private float oldY; ...
  • 对于已添加到文本字段的UIScrollView ,请尝试将delaysContentTouches属性设置为YES 。 这应该允许您在触摸时滚动,然后在文本字段中拖动。 Try setting the delaysContentTouches property to YES for the UIScrollView to which you have added to text field. This should allow you to scroll if you touch and then drag ...
  • 如果启用了UIScrollView中的滚动,则touchMoved事件不会传播到滚动视图内容。 如何解决方法取决于您想实现的目标。 在我的应用程序中,我只需要在UIScrollView拖动一个对象,并在contentView触摸处理程序中做了以下操作: 在touchesBegan:事件中,我检查了是否挖掘了要拖动的对象。 如果是 - 则在UIScrollView中禁用滚动 然后当滚动被禁用时,我的内容视图开始接收touchesMoved事件,我可以在那里“拖动”我的对象。 在touchesEnded:我重新 ...

相关文章

更多

最新问答

更多
  • 获取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的基本操作命令。。。