- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在为一个名为 Opinionated 的开源项目开发 Android 前端。这是我的第一次android开发经历。该应用程序是一个新闻聚合器,可将用户链接到与他们正在阅读的文章相似的文章。后端生成 JSON 文件,我需要解析这些文件来创建按钮/ TextView 等...
我的 android 项目的 asset 文件夹中存储有 JSON 文件,并且有一个函数可以将 JSON 文件的内容作为字符串返回。我使用此字符串创建 JSONObject,但是当我尝试使用此字符串创建 JSONArray 时,会引发异常。
我的 JSON 文件如下所示:
{
"article":{
"title" : "Justices Hearing Arguments on ‘One Person, One Vote’",
"description" : "The Supreme Court will address a voting rights case that has the potential to shift political power from urban areas to rural ones. The Supreme Court has never definitively ruled on who must be counted in voting districts: all residents or just eligible voters?",
"author" : "ADAM LIPTAK",
"date" : "2015-12-08",
"link" : "http://www.nytimes.com/2015/12/09/us/politics/supreme-court-to-hear-arguments-on-one-person-one-vote.html?hp&action=click&pgtype=Homepage&clickSource=story-heading&module=first-column-region®ion=top-news&WT.nav=top-news",
"image" : "http://static01.nyt.com/images/2015/12/08/us/09scotus-web/09scotus-web-master675.jpg",
"imageCaption" : "Voters in Columbus, Ohio, last month",
"body" : "WASHINGTON — A closely divided Supreme Court on Tuesday struggled to decide “what kind of democracy people want,” as Justice Stephen G. Breyer put it during an argument over the meaning of the constitutional principle of “one person one vote.” The case basic question in the case, Evenwel v. Abbott, No. 14-940, is who must be counted in drawing voting districts: all residents or just eligible voters? The difference matters, because people who are not eligible to vote — children, immigrants here legally who are not citizens, unauthorized immigrants, people disenfranchised for committing felonies, prisoners — are not spread evenly across the country. With the exception of prisoners, they tend to be concentrated in urban areas. Their presence amplifies the voting power of people eligible to vote in urban areas, usually helping Democrats. Rural areas that lean Republican, by contrast, usually have higher percentages of residents eligible to vote. Continue reading the main story. RELATED COVERAGE Q. and A.: Examining a Voting Rights CaseDEC. 8, 2015 The John J. Moran Medium Security Prison in Cranston, R.I. A lawsuit filed in that state by the American Civil Liberties Union objects to counting prisoners when drawing voting districts.Sidebar: A.C.L.U.’s Own Arguments May Work Against It in Voting Rights CaseOCT. 12, 2015 Voting booths in Houston. Two Texas plaintiffs are challenging State Senate districts apportioned by the number of residents rather than eligible voters, saying it dilutes their voting power.Supreme Court Agrees to Settle Meaning of ‘One Person One Vote’MAY 26, 2015 The court’s decision in the case, expected by June, has the potential to shift political power from urban areas to rural ones, a move that would provide a big boost to Republican voters in many parts of the nation. Chief Justice John G. Roberts Jr. seemed attracted to counting only voters. “It is called ‘one person one vote,’” he said. “That does seem designed to protect voters.” But Justice Sonia Sotomayor said there were other interests at stake. “There’s a voting interest,” she said, “but there is also a representational interest.” Continue reading the main story RELATED IN OPINION Contributing Op-Ed Writer: The Supreme Court’s Identity Crisis on Voting RightsMARCH 19, 2015 Justice Anthony M. Kennedy seemed to be looking for a middle ground. “You should at least give some consideration to the disparity you have among voters” in different voting districts, he said. The “one person one vote” principle, rooted in cases from the 1960s that revolutionized democratic representation in the United States, applies to the entire American political system aside from the Senate, where voters from states with small populations have vastly more voting power than those with large ones. Everywhere else, voting districts must have very close to the same populations. But the Supreme Court has never definitively ruled on who must be counted. Tuesday’s case, a challenge to voting districts for the Texas Senate, was brought by Sue Evenwel and Edward Pfenninger. They are represented by the Project on Fair Representation, a small conservative advocacy group that has been active in cases concerning race and voting. The group was on the winning side in 2013 in Shelby County v. Holder, which effectively struck down the heart of the Voting Rights Act, freeing nine states, mostly in the South, to change their election laws without advance federal approval. The group is also behind a challenge to affirmative action in admissions at the University of Texas at Austin to be argued on Wednesday. In court papers, Ms. Evenwel and Mr. Pfenninger said that they lived in “districts among the most overpopulated with eligible voters” and that “there are voters or potential voters in Texas whose Senate votes are worth approximately one and one-half times that of appellants.” Last year, a three-judge panel of the Federal District Court in Austin dismissed the case, saying that “the Supreme Court has generally used total population as the metric of comparison.” At the same time, the panel said, the Supreme Court has never required any particular standard. The choice, the panel said, belongs to the states. Continue reading the main story RECENT COMMENTS John Graubard 18 minutes ago At the time the Constitution was adopted only white property owning male citizens had the right to vote. Should we go back to that time? ... michjas 18 minutes ago Most of the non-voting population at issue here consists of the U.S.'s 75 million children. And of that total, 20 million are Hispanic,... raduray 18 minutes ago If we counted only voters, it would favor communities with smaller families (generally more liberal), as children don't vote. Plaintiffs,... SEE ALL COMMENTS WRITE A COMMENT Almost all states and localities count everyone, and the Constitution requires “counting the whole number of persons in each state” for apportioning seats in the House of Representatives among the states. There are practical problems, many political scientists say, in finding reliable data to count only eligible voters. Federal appeals courts have uniformly ruled that counting everyone is permissible, and one court has indicated that it is required. In the process, though, several judges have acknowledged that the Supreme Court’s decisions provide support for both approaches. The federal appeals court in New Orleans said the issue “presents a close question,” partly because the Supreme Court had been “somewhat evasive in regard to which population must be equalized.” In 1990, Judge Alex Kozinski, in a partial dissent from a decision of the federal appeals court in San Francisco, said there were respectable arguments on both sides. CONTINUE READING THE MAIN STORY 341 COMMENTS Counting everyone, he said, ensures “representational equality,” with elected officials tending to the interests of the same number of people, whether they are voters or not. Counting only eligible voters, on the other hand, he said, vindicates the principle that voters “hold the ultimate political power in our democracy.” In 2001, the Supreme Court turned down an opportunity to decide the question, in another case from Texas. “The one-person-one-vote principle may, in the end, be of little consequence if we decide that each jurisdiction can choose its own measure of population,” Justice Clarence Thomas wrote. “But as long as we sustain the one-person-one-vote principle, we have an obligation to explain to states and localities what it actually means.”",
"file" : "exArt1.json",
"template" : "top",
"similarArticles" : ["exArt4.json", "exArt5.json"]}}
我创建和使用 JSON 对象的代码如下:
try {
JSONObject main_obj = new JSONObject(loadJSONFromAsset());
JSONArray jarray= main_obj.getJSONArray("article");
JSONObject article = jarray.getJSONObject(0);
String title=article.getString("title");
Button button = new Button(this);
button.setText(title);
linearLayout.addView(button);
} catch (JSONException e) {
e.printStackTrace();
}
任何帮助/指示将不胜感激,谢谢!
最佳答案
试试这个:
try {
JSONObject main_obj = new JSONObject(loadJSONFromAsset());
JSONObject article= main_obj.getJSONObject("article");
String title=article.getString("title");
Button button = new Button(this);
button.setText(title);
linearLayout.addView(button);
} catch (JSONException e) {
e.printStackTrace();
}
关于java - 解析 Android 的 JSON 文件时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36366128/
我一直在使用 AJAX 从我正在创建的网络服务中解析 JSON 数组时遇到问题。我的前端是一个简单的 ajax 和 jquery 组合,用于显示从我正在创建的网络服务返回的结果。 尽管知道我的数据库查
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我在尝试运行 Android 应用程序时遇到问题并收到以下错误 java.lang.NoClassDefFoundError: com.parse.Parse 当我尝试运行该应用时。 最佳答案 在这
有什么办法可以防止etree在解析HTML内容时解析HTML实体吗? html = etree.HTML('&') html.find('.//body').text 这给了我 '&' 但我想
我有一个有点疯狂的例子,但对于那些 JavaScript 函数作用域专家来说,它看起来是一个很好的练习: (function (global) { // our module number one
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 8 年前。 Improve th
我需要编写一个脚本来获取链接并解析链接页面的 HTML 以提取标题和其他一些数据,例如可能是简短的描述,就像您链接到 Facebook 上的内容一样。 当用户向站点添加链接时将调用它,因此在客户端启动
在 VS Code 中本地开发时,包解析为 C:/Users//AppData/Local/Microsoft/TypeScript/3.5/node_modules/@types//index而不是
我在将 json 从 php 解析为 javascript 时遇到问题 这是我的示例代码: //function MethodAjax = function (wsFile, param) {
我在将 json 从 php 解析为 javascript 时遇到问题 这是我的示例代码: //function MethodAjax = function (wsFile, param) {
我被赋予了将一种语言“翻译”成另一种语言的工作。对于使用正则表达式的简单逐行方法来说,源代码过于灵活(复杂)。我在哪里可以了解更多关于词法分析和解析器的信息? 最佳答案 如果你想对这个主题产生“情绪化
您好,我在解析此文本时遇到问题 { { { {[system1];1;1;0.612509325}; {[system2];1;
我正在为 adobe after effects 在 extendscript 中编写一些代码,最终变成了 javascript。 我有一个数组,我想只搜索单词“assemble”并返回整个 jc3_
我有这段代码: $(document).ready(function() { // }); 问题:FB_RequireFeatures block 外部的代码先于其内部的代码执行。因此 who
背景: netcore项目中有些服务是在通过中间件来通信的,比如orleans组件。它里面服务和客户端会指定网关和端口,我们只需要开放客户端给外界,服务端关闭端口。相当于去掉host,这样省掉了些
1.首先贴上我试验成功的代码 复制代码 代码如下: protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
什么是 XML? XML 指可扩展标记语言(eXtensible Markup Language),标准通用标记语言的子集,是一种用于标记电子文件使其具有结构性的标记语言。 你可以通过本站学习 X
【PHP代码】 复制代码 代码如下: $stmt = mssql_init('P__Global_Test', $conn) or die("initialize sto
在SQL查询分析器执行以下代码就可以了。 复制代码代码如下: declare @t varchar(255),@c varchar(255) declare table_cursor curs
前言 最近练习了一些前端算法题,现在做个总结,以下题目都是个人写法,并不是标准答案,如有错误欢迎指出,有对某道题有新的想法的友友也可以在评论区发表想法,互相学习🤭 题目 题目一: 二维数组中的
我是一名优秀的程序员,十分优秀!