gpt4 book ai didi

java - 为什么 JSONArray 不提供 contains() 方法?

转载 作者:行者123 更新时间:2023-12-01 12:06:33 26 4
gpt4 key购买 nike

既然org.json.JSONArray在内部使用ArrayList,为什么他们不提供公共(public)contains()方法呢?

最佳答案

JSON 基于 JavaScript,而 JavaScript 在 array 类型上没有 contains() 方法。请参阅https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

有一个 indexOf() 方法 since version 5.1但它成为 2014 年发布的 JavaScript 6 的标准。因此 JSON API 对于此方法来说也太旧了。

Also the standard document状态:

JSON was inspired by the object literals of JavaScript aka ECMAScript as defined in the ECMAScript Language Specification, third Edition 1. It does not attempt to impose ECMAScript’s internal data representations on other programming languages. Instead, it shares a small subset of ECMAScript’s textual representations with all other programming languages.

(我的亮点)。所以我的假设是 API 设计者的目标是简单的设计。

关于java - 为什么 JSONArray 不提供 contains() 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27548334/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com