android - 我怎样才能从这个 JSON 字符串中删除这个符号?

标签 android json

如何从这个 JSON 字符串中删除“-”?如果我执行 .replace("-","") ,它将从所有位置删除“-”。

屏幕上没有显示任何错误。

"{"status":"ok","totalResults":38,-"articles":[-{-"source":{"id":null,"name":"Hindustantimes.com"},"author":"HT Correspondent","title":"‘I call you Didi, your slap a blessing for me’: PM Modi hits back at Mamata Banerjee - Hindustan Times","description":"PM Modi said, Mamata Banerjee would have had to worry so much about losing if she had showed the courage to slap her colleagues who cheated the poor in the chit fund scam.","url":"https://www.hindustantimes.com/lok-sabha-elections/your-slap-would-be-a-blessing-pm-modi-hits-back-at-mamata-banerjee/story-LuWAMTRdGrII3xZXSiZU8K.html","urlToImage":"https://www.hindustantimes.com/rf/image_size_960x540/HT/p2/2019/05/09/Pictures/narendra-modi_a713213e-7229-11e9-9308-6ffbdc5c45a7.jpg","publishedAt":"2019-05-09T07:12:00Z","content":"Back in Bengal on the campaign trail, Prime Minister Narendra Modi on Thursday launched a scathing attack at chief minister Mamata Banerjee for her governance record. But before he got down to critiquing her stint as a two-time chief minister, PM Modi also hu… [+1586 chars]"},-{-"source":{"id":null,"name":"Thehansindia.com"},"author":"Saritha","title":"Psychological distress associated with emotional eating and obesity - The Hans India","description":"Researchers draw link between psychological distress, emotional eating and obesity.","url":"https://www.thehansindia.com/life-style/health/psychological-distress-associated-with-emotional-eating-and-obesity-527919","urlToImage":"https://s3.ap-south-1.amazonaws.com/hansindia-bucket/h-upload/feeds/2019/05/09/172906-eating.jpg?width=500&height=300","publishedAt":"2019-05-09T07:03:03Z","content":"Washington: People with lower incomes may be more likely to have obesity as a result of psychological distress that gives rise to emotional eating, recent findings suggest. \r\nAs part of the latest study, as team of researchers explored whether the relationshi… [+1697 chars]"},-{-"source":{"id":null,"name":"Moneycontrol.com"},"author":null,"title":"Market Live: Indices near day's low, Nifty slips to 11,300; Essel Group stocks jump - Moneycontrol.com","description":"Among sectors, metal, pharma and bank have come under pressure","url":"https://www.moneycontrol.com/news/business/markets/stock-market-live-updates-bse-nse-nifty-sensex-corporate-announcements-2-3950211.html","urlToImage":"https://static-news.moneycontrol.com/static-mcnews/2018/07/Sensex_Nifty_BSE__traders-770x433.jpg","publishedAt":"2019-05-09T06:57:38Z","content":"Brokerages View: Source: CNBC-TV18\r\nMorgan Stanley on Reliance IndustriesDowngrade to equal-weight, target at Rs 1,349 per shareExpect 2-year earnings upswing to reverseRising glut in gas & polyester markets could also slow growth into 2020\r\nMorgan Stanle… [+1531 chars]"},-{-"source":{"id":null,"name":"Hindustantimes.com"},"author":"HT Correspondent","title":"SC dismisses ex-BSF jawan Tej Bahadur’s plea against rejection of nomination - Hindustan Times","description":"SC dismisses sacked BSF jawan Tej Bahadur’s plea challenging EC scrapping his Varanasi nomination for LS polls","url":"https://www.hindustantimes.com/india-news/sc-dismisses-sacked-bsf-jawan-tej-bahadur-s-plea-challenging-ec-scrapping-his-varanasi-nomination-for-ls-polls/story-Nhf2lgyiU1CllH6msfEeJN.html","urlToImage":"https://www.hindustantimes.com/rf/image_size_960x540/HT/p2/2019/05/09/Pictures/facebook-bahadur-arrangements-battalion-bahadur-social-showing_9bf23590-7226-11e9-9308-6ffbdc5c45a7.jpg","publishedAt":"2019-05-09T06:50:00Z","content":"The Supreme Court has dismissed sacked BSF jawan Tej Bahadur’s plea challenging Election Commission’s decision to scrap his Varanasi nomination for Lok Sabha polls.\r\nTej Bahadur Yadav, who moved the Supreme Court on May 6, termed the decision of the poll pane… [+1165 chars]"},-{-"source":{"id":null,"name":"Odishatv.in"},"author":"IANS","title":"It’s Unfair, says SOTY 2 Actress Ananya Panday in an Exclusive Interview - Odisha Television Ltd.","description":"By Durga ChakravartyNew Delhi: Coming from a Bollywood background cannot stop one from having a dream, asserts actor Chunky Panday's daughter Ananya Panday whose debut film \"Student of the Year 2\" is set to hit the screens.Ananya says it was always h","url":"https://odishatv.in/entertainment/its-unfair-says-soty-2-actress-ananya-panday-in-an-exclusive-interview-369207","urlToImage":"https://s3-ap-south-1.amazonaws.com/cdn.odishatv.in/wp-content/uploads/2019/04/13110658/ananya.jpg","publishedAt":"2019-05-09T06:43:00Z","content":"By Durga Chakravarty\r\nNew Delhi: Coming from a Bollywood background cannot stop one from having a dream, asserts actor Chunky Panday’s daughter Ananya Panday whose debut film “Student of the Year 2” is set to hit the screens.\r\nAnanya says it was always her dr… [+2348 chars]"},-{-"source":{"id":"the-times-of-india","name":"The Times of India"},"author":"Times Of India","title":"Citizenship row: SC dismisses plea seeking direction to debar Rahul Gandhi from contesting Lok Sabha pol - Times of India","description":"India News: The SC has dismissed a petition seeking to direct the EC to debar Rahul Gandhi from contesting the LS polls alleging he had “voluntarily acquired Brit","url":"https://timesofindia.indiatimes.com/india/sc-dismisses-plea-seeking-direction-to-debar-rahul-from-contesting-ls-polls/articleshow/69246991.cms","urlToImage":"https://static.toiimg.com/thumb/msid-69246992,width-1070,height-580,imgsize-170056,resizemode-6,overlay-toi_sw,pt-32,y_pad-40/photo.jpg","publishedAt":"2019-05-09T06:28:00Z","content":"Copyright © 2019 Bennett, Coleman & Co. Ltd. All rights reserved. For reprint rights: Times Syndication Service"},-{-"source":{"id":null,"name":"Sammobile.com"},"author":"SamMobile","title":"Galaxy Note 10 may use Samsung’s latest 64-megapixel camera - SamMobile","description":"Samsung has unveiled a new 64-megapixel ISOCELL Bright GW1 image sensor today which is great news for the Galaxy Note ...","url":"https://www.sammobile.com/2019/05/09/galaxy-note-10-samsungs-64-megapixel-camera/","urlToImage":"https://www.sammobile.com/wp-content/uploads/2019/05/galaxy-note-10-isocell-720x520.jpg","publishedAt":"2019-05-09T06:17:27Z","content":"Samsung has unveiled a new 64-megapixel ISOCELL Bright GW1 image sensor today which is great news for the Galaxy Note 10. Given that the new sensor is expected to enter mass production in the second half of this year, there’s a good chance that we might see i… [+1717 chars]"},-{-"source":{"id":null,"name":"News18.com"},"author":"News18.com","title":"SC Collegium Rejects Centre's Objection to Elevation of Two Judges, Reiterates Names - News18","description":"The Centre had on Wednesday sent back the two names, citing seniority and representation of regions as the reason behind the move.","url":"https://www.news18.com/news/india/sc-collegium-rejects-centres-objection-to-elevation-of-two-judges-reiterates-names-2134145.html","urlToImage":"https://images.news18.com/ibnlive/uploads/2017/11/supreme-court-of-india.jpg","publishedAt":"2019-05-09T05:42:00Z","content":"New Delhi: Rejecting the Centres objections, the Supreme Court Collegium has reiterated the names of Justices Aniruddha Bose and AS Bopanna for elevation to the apex court, making it mandatory for the government to now appoint them.The Collegium, in response … [+2014 chars]"},-{-"source":{"id":null,"name":"Hindustantimes.com"},"author":"HT Correspondent","title":"NASA images show darkness engulfed Bhubaneswar after cyclone Fani - Hindustan Times","description":"NASA’s images compare the situation in Bhubaneswar and the nighttime lights in Cuttack, Odisha’s second largest city north of the state capital, before and after Cyclone Fani, made landfall.","url":"https://www.hindustantimes.com/india-news/nasa-images-show-how-darkness-engulfed-bhubaneswar-after-cyclone-fani/story-dHMzkoUeB8tzCYEelWDK6N.html","urlToImage":"https://www.hindustantimes.com/rf/image_size_960x540/HT/p2/2019/05/09/Pictures/_1cc20868-721c-11e9-9308-6ffbdc5c45a7.jpg","publishedAt":"2019-05-09T05:41:00Z","content":"US space agency NASA has released images showing the impact of Cyclone Fani, one of the worst storms to hit India in two decades, as millions were left without power after it barrelled through the eastern state’s coastal areas.\r\nNASA’s images compare the situ… [+2633 chars]"},-{-"source":{"id":null,"name":"Ndtv.com"},"author":null,"title":"\"Privacy Not A Luxury Good, Must Be Equally Available\": Sundar Pichai - NDTV News","description":"Privacy cannot be a \"luxury good\" that's only available to people who can afford to buy premium products and services, Google CEO Sundar Pichai has said.","url":"https://www.ndtv.com/india-news/google-ceo-sundar-pichai-says-privacy-cannot-be-a-luxury-good-must-be-equally-available-to-everyone-2035066","urlToImage":"https://c.ndtvimg.com/2018-12/oq25ik3o_sundar-pichai-afp_625x300_11_December_18.jpg","publishedAt":"2019-05-09T05:28:00Z","content":"Sundar Pichai also called on the US to introduce a new legislation for protecting data.New York: Privacy cannot be a \"luxury good\" that's only available to people who can afford to buy premium products and services, Google CEO Sundar Pichai has said.\r\nIn an o… [+1674 chars]"},-{-"source":{"id":"the-times-of-india","name":"The Times of India"},"author":null,"title":"IPL 2019: When Keemo Paul came back to haunt Khaleel Ahmed - Times of India","description":"Cricket News: It was at the ICC U-19 World Cup final in 2016 when Keemo Paul scored the winning runs off Khaleel Ahmed, and the script unfolded in a similar fashion","url":"https://timesofindia.indiatimes.com/sports/cricket/ipl/top-stories/ipl-2019-when-keemo-paul-came-back-to-haunt-khaleel-ahmed/articleshow/69245732.cms","urlToImage":"https://static.toiimg.com/thumb/msid-69245876,width-1070,height-580,imgsize-1813959,resizemode-6,overlay-toi_sw,pt-32,y_pad-40/photo.jpg","publishedAt":"2019-05-09T05:23:18Z","content":"NEW DELHI: On Wednesday night, Delhi Capitals (DC) managed their first win in an Indian Premier League (IPL) play-off match in five attempts across 12 years. A nail-biting Eliminator saw them ousting Sunrisers Hyderabad (SRH) with a two-wicket win. They will … [+1806 chars]"}}";

QueryUtils.java

public static ArrayList<String> extractNews(){
    ArrayList<String> news = new ArrayList<String>();
    try{

        JSONObject baseJSONObj = new JSONObject(SAMPLE_JSON);

        JSONArray baseJsonObject = baseJSONObj.getJSONArray("articles");

        for(int i = 0; baseJsonObject.length() < i ; i++) {
           // JSONObject jsonObject = baseJSONObj.getJSONObject(i);
            String article = baseJSONObj.getString("title");
            String a = new String(article);
            news.add(a);
        }


    }catch (JSONException j){

    }

    return news;
}

最佳答案

如果您只想删除第一个“-”,您可以像这样使用 replaceFirst :

String yourString = json.replaceFirst("-","")

关于android - 我怎样才能从这个 JSON 字符串中删除这个符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56058052/

相关文章:

javascript - 转置 JSON 数据

json - 将 JSON 解析为结构

android - putExtra treeMap 返回 HashMap cannot be cast to TreeMap android

android - 在按钮的中心点之间画线,找不到中心

android - 单击项目时如何更新 recyclerviews 其他项目?

php - 为什么我不能将零设置为数组中的第一个键?

json - 如何在 Jekyll 中从 JSON 加载数据

java - 添加计时器并设置大小到 viewpager

android - 为什么它在开始监听之前不休眠 3 秒?

java - 如何使用 Jackson 反序列化 Map<?, ?> ?