• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JsonParser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.grack.nanojson.JsonParser的典型用法代码示例。如果您正苦于以下问题:Java JsonParser类的具体用法?Java JsonParser怎么用?Java JsonParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JsonParser类属于com.grack.nanojson包,在下文中一共展示了JsonParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: suggestionList

import com.grack.nanojson.JsonParser; //导入依赖的package包/类
@Override
public List<String> suggestionList(String query, String contentCountry) throws IOException, ExtractionException {
    List<String> suggestions = new ArrayList<>();

    Downloader dl = NewPipe.getDownloader();

    String url = "https://api-v2.soundcloud.com/search/queries"
            + "?q=" + URLEncoder.encode(query, CHARSET_UTF_8)
            + "&client_id=" + SoundcloudParsingHelper.clientId()
            + "&limit=10";

    String response = dl.download(url);
    try {
        JsonArray collection = JsonParser.object().from(response).getArray("collection");
        for (Object suggestion : collection) {
            if (suggestion instanceof JsonObject) suggestions.add(((JsonObject) suggestion).getString("query"));
        }

        return suggestions;
    } catch (JsonParserException e) {
        throw new ParsingException("Could not parse json response", e);
    }
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:24,代码来源:SoundcloudSuggestionExtractor.java


示例2: getAudioStreams

import com.grack.nanojson.JsonParser; //导入依赖的package包/类
@Override
public List<AudioStream> getAudioStreams() throws IOException, ExtractionException {
    List<AudioStream> audioStreams = new ArrayList<>();
    Downloader dl = NewPipe.getDownloader();

    String apiUrl = "https://api.soundcloud.com/i1/tracks/" + urlEncode(getId()) + "/streams"
            + "?client_id=" + urlEncode(SoundcloudParsingHelper.clientId());

    String response = dl.download(apiUrl);
    JsonObject responseObject;
    try {
        responseObject = JsonParser.object().from(response);
    } catch (JsonParserException e) {
        throw new ParsingException("Could not parse json response", e);
    }

    String mp3Url = responseObject.getString("http_mp3_128_url");
    if (mp3Url != null && !mp3Url.isEmpty()) {
        audioStreams.add(new AudioStream(mp3Url, MediaFormat.MP3, 128));
    } else {
        throw new ExtractionException("Could not get SoundCloud's track audio url");
    }

    return audioStreams;
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:26,代码来源:SoundcloudStreamExtractor.java


示例3: setupNextStreamsAjax

import com.grack.nanojson.JsonParser; //导入依赖的package包/类
private void setupNextStreamsAjax(Downloader downloader) throws IOException, ReCaptchaException, ParsingException {
    String ajaxDataRaw = downloader.download(nextStreamsUrl);
    try {
        JsonObject ajaxData = JsonParser.object().from(ajaxDataRaw);

        String htmlDataRaw = "<table><tbody id=\"pl-load-more-destination\">" + ajaxData.getString("content_html") + "</tbody></table>";
        nextStreamsAjax = Jsoup.parse(htmlDataRaw, nextStreamsUrl);

        String nextStreamsHtmlDataRaw = ajaxData.getString("load_more_widget_html");
        if (!nextStreamsHtmlDataRaw.isEmpty()) {
            nextStreamsUrl = getNextStreamsUrlFrom(Jsoup.parse(nextStreamsHtmlDataRaw, nextStreamsUrl));
        } else {
            nextStreamsUrl = "";
        }
    } catch (JsonParserException e) {
        throw new ParsingException("Could not parse json data for next streams", e);
    }
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:19,代码来源:YoutubePlaylistExtractor.java


示例4: setupNextStreamsAjax

import com.grack.nanojson.JsonParser; //导入依赖的package包/类
private void setupNextStreamsAjax(Downloader downloader) throws IOException, ReCaptchaException, ParsingException {
    String ajaxDataRaw = downloader.download(nextStreamsUrl);
    try {
        JsonObject ajaxData = JsonParser.object().from(ajaxDataRaw);

        String htmlDataRaw = ajaxData.getString("content_html");
        nextStreamsAjax = Jsoup.parse(htmlDataRaw, nextStreamsUrl);

        String nextStreamsHtmlDataRaw = ajaxData.getString("load_more_widget_html");
        if (!nextStreamsHtmlDataRaw.isEmpty()) {
            nextStreamsUrl = getNextStreamsUrlFrom(Jsoup.parse(nextStreamsHtmlDataRaw, nextStreamsUrl));
        } else {
            nextStreamsUrl = "";
        }
    } catch (JsonParserException e) {
        throw new ParsingException("Could not parse json data for next streams", e);
    }
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:19,代码来源:YoutubeChannelExtractor.java


示例5: load

import com.grack.nanojson.JsonParser; //导入依赖的package包/类
public static void load(Reader reader, boolean resource) throws JsonParserException {
    JsonObject parentObject = JsonParser.object().from(reader);
    String code = parentObject.getString("code");
    String name = parentObject.getString("name");
    String inherit = parentObject.getString("inherit");

    if (code == null) throw new LocaleException("Locale 'code' key must be set!");
    if (name == null) throw new LocaleException("Locale 'name' key must be set!");

    Locale locale = new Locale(code, name);
    locale.inherit(inherit);
    JsonObject translations = parentObject.getObject("translations");
    for (Map.Entry<String, Object> entry : translations.entrySet())
        locale.addTranslation(entry.getKey(), (String) entry.getValue());
    locales.put(code, locale);

    if (resource) resourceLocales.add(code); else fileLocales.add(code);
}
 
开发者ID:FRC5333,项目名称:Parlez-Vous,代码行数:19,代码来源:LocaleLoader.java


示例6: doInBackground

import com.grack.nanojson.JsonParser; //导入依赖的package包/类
@Override
protected ServerListEntry[] doInBackground()
        throws Exception {
    LogUtil.getLogger().log(Level.FINE, "ClassiCubeNetGetServerListWorker");
    final String serverListString = HttpUtil.downloadString(SERVER_LIST_URL);

    final ArrayList<ServerListEntry> servers = new ArrayList<>();

    final JsonArray array = JsonParser.object().from(serverListString).getArray("servers");

    for (final Object rawRow : array) { //iterate through and add servers to the list
        final JsonObject row = (JsonObject) rawRow;
        final ServerListEntry info = new ServerListEntry();

        info.flag = "";
        info.hash = row.getString("hash");
        info.maxPlayers = row.getInt("maxplayers");
        info.name = row.getString("name");
        info.players = row.getInt("players");
        info.uptime = row.getInt("uptime");
        info.software = row.getString("software");
        servers.add(info); //add it
    }
    return servers.toArray(new ServerListEntry[servers.size()]); //return
}
 
开发者ID:fragmer,项目名称:ClassiCubeLauncher,代码行数:26,代码来源:ClassiCubeNetSession.java


示例7: onFetchPage

import com.grack.nanojson.JsonParser; //导入依赖的package包/类
@Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {

    playlistId = getUrlIdHandler().getId(getOriginalUrl());
    String apiUrl = "https://api.soundcloud.com/playlists/" + playlistId +
            "?client_id=" + SoundcloudParsingHelper.clientId() +
            "&representation=compact";

    String response = downloader.download(apiUrl);
    try {
        playlist = JsonParser.object().from(response);
    } catch (JsonParserException e) {
        throw new ParsingException("Could not parse json response", e);
    }
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:16,代码来源:SoundcloudPlaylistExtractor.java


示例8: onFetchPage

import com.grack.nanojson.JsonParser; //导入依赖的package包/类
@Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {

    userId = getUrlIdHandler().getId(getOriginalUrl());
    String apiUrl = "https://api.soundcloud.com/users/" + userId +
            "?client_id=" + SoundcloudParsingHelper.clientId();

    String response = downloader.download(apiUrl);
    try {
        user = JsonParser.object().from(response);
    } catch (JsonParserException e) {
        throw new ParsingException("Could not parse json response", e);
    }
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:15,代码来源:SoundcloudChannelExtractor.java


示例9: resolveFor

import com.grack.nanojson.JsonParser; //导入依赖的package包/类
/**
 * Call the endpoint "/resolve" of the api.<p>
 * 
 * See https://developers.soundcloud.com/docs/api/reference#resolve
 */
public static JsonObject resolveFor(Downloader downloader, String url) throws IOException, ReCaptchaException, ParsingException {
    String apiUrl = "https://api.soundcloud.com/resolve"
            + "?url=" + URLEncoder.encode(url, "UTF-8")
            + "&client_id=" + clientId();

    try {
        return JsonParser.object().from(downloader.download(apiUrl));
    } catch (JsonParserException e) {
        throw new ParsingException("Could not parse json response", e);
    }
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:17,代码来源:SoundcloudParsingHelper.java


示例10: suggestionList

import com.grack.nanojson.JsonParser; //导入依赖的package包/类
@Override
public List<String> suggestionList(String query, String contentCountry) throws IOException, ExtractionException {
    Downloader dl = NewPipe.getDownloader();
    List<String> suggestions = new ArrayList<>();

    String url = "https://suggestqueries.google.com/complete/search"
            + "?client=" + "youtube" //"firefox" for JSON, 'toolbar' for xml
            + "&jsonp=" + "JP"
            + "&ds=" + "yt"
            + "&hl=" + URLEncoder.encode(contentCountry, CHARSET_UTF_8)
            + "&q=" + URLEncoder.encode(query, CHARSET_UTF_8);

    String response = dl.download(url);
    // trim JSONP part "JP(...)"
    response = response.substring(3, response.length()-1);
    try {
        JsonArray collection = JsonParser.array().from(response).getArray(1, new JsonArray());
        for (Object suggestion : collection) {
            if (!(suggestion instanceof JsonArray)) continue;
            String suggestionStr = ((JsonArray)suggestion).getString(0);
            if (suggestionStr == null) continue;
            suggestions.add(suggestionStr);
        }

        return suggestions;
    } catch (JsonParserException e) {
        throw new ParsingException("Could not parse json response", e);
    }
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:30,代码来源:YoutubeSuggestionExtractor.java


示例11: doImport

import com.grack.nanojson.JsonParser; //导入依赖的package包/类
@Override
@Nullable
public MindMap doImport(@Nonnull final MindMapPanel panel, @Nonnull final DialogProvider dialogProvider, @Nullable final Topic actionTopic, @Nonnull @MustNotContainNull final Topic[] selectedTopics) throws Exception {
  final File file = this.selectFileForExtension(panel, Texts.getString("MMDImporters.Mindmup2MindMap.openDialogTitle"), "mup", "Mindmup files (.MUP)", Texts.getString("MMDImporters.ApproveImport"));

  if (file == null) {
    return null;
  }
  
  final JsonObject parsedJson;
  parsedJson = JsonParser.object().from(FileUtils.readFileToString(file, "UTF-8"));

  MindMap resultedMap = null;

  final Number formatVersion = parsedJson.getNumber("formatVersion");
  if (formatVersion == null) {
    dialogProvider.msgError(null,Texts.getString("MMDImporters.Mindmup2MindMap.Error.WrongFormat"));
  } else {
    resultedMap = new MindMap(null, true);
    resultedMap.setAttribute(MindMapPanel.ATTR_SHOW_JUMPS, "true");

    final Topic mindMapRoot = Assertions.assertNotNull(resultedMap.getRoot());
    final Map<Long, Topic> mapTopicId = new HashMap<Long, Topic>();

    parseTopic(resultedMap, null, mindMapRoot, parsedJson, mapTopicId);

    if (!mindMapRoot.getExtras().containsKey(Extra.ExtraType.FILE)) {
      mindMapRoot.setExtra(new ExtraFile(new MMapURI(null, file, null)));
    }

    final JsonArray links = parsedJson.getArray("links");
    if (links != null) {
      processLinks(resultedMap, links, mapTopicId);
    }
  }
  return resultedMap;
}
 
开发者ID:raydac,项目名称:netbeans-mmd-plugin,代码行数:38,代码来源:Mindmup2MindMapImporter.java


示例12: loadDataFromNetwork

import com.grack.nanojson.JsonParser; //导入依赖的package包/类
@Override
public JsonObject loadDataFromNetwork() throws Exception {
    URL baseUrl = new URL("http://www.progscrape.com/feed.json"
            + (query == null ? "" : "?search=" + URLEncoder.encode(query, "UTF-8")));
    Log.d("feed", "Making request to " + baseUrl);
    HttpURLConnection conn = getUrlFactory().open(baseUrl);

    try (InputStream in = conn.getInputStream()) {
        JsonObject rawFeed = JsonParser.object().from(in);
        Log.d("feed", "Successfully retrieved feed");
        return rawFeed;
    }
}
 
开发者ID:mmastrac,项目名称:progscrape-android,代码行数:14,代码来源:FeedRequest.java


示例13: checkEventTypeSchemaValid

import com.grack.nanojson.JsonParser; //导入依赖的package包/类
public static void checkEventTypeSchemaValid(final String jsonInString) throws InvalidEventTypeException {
    try {
        JsonParser.any().from(jsonInString);
    } catch (final JsonParserException jpe) {
        throw new InvalidEventTypeException("schema must be a valid json: " + jpe.getMessage());
    }
}
 
开发者ID:zalando,项目名称:nakadi,代码行数:8,代码来源:JsonUtils.java


示例14: search

import com.grack.nanojson.JsonParser; //导入依赖的package包/类
@Override
public InfoItemSearchCollector search(String query, int page, String languageCode, Filter filter) throws IOException, ExtractionException {
    InfoItemSearchCollector collector = getInfoItemSearchCollector();

    Downloader dl = NewPipe.getDownloader();

    String url = "https://api-v2.soundcloud.com/search";

    switch (filter) {
        case STREAM:
            url += "/tracks";
            break;
        case CHANNEL:
            url += "/users";
            break;
        case PLAYLIST:
            url += "/playlists";
            break;
        case ANY:
            // Don't append any parameter to search for everything
        default:
            break;
    }

    url += "?q=" + URLEncoder.encode(query, CHARSET_UTF_8)
            + "&client_id=" + SoundcloudParsingHelper.clientId()
            + "&limit=10"
            + "&offset=" + Integer.toString(page * 10);

    JsonArray searchCollection;
    try {
        searchCollection = JsonParser.object().from(dl.download(url)).getArray("collection");
    } catch (JsonParserException e) {
        throw new ParsingException("Could not parse json response", e);
    }

    if (searchCollection.size() == 0) {
        throw new NothingFoundException("Nothing found");
    }

    for (Object result : searchCollection) {
        if (!(result instanceof JsonObject)) continue;
        //noinspection ConstantConditions
        JsonObject searchResult = (JsonObject) result;
        String kind = searchResult.getString("kind", "");
        switch (kind) {
            case "user":
                collector.commit(new SoundcloudChannelInfoItemExtractor(searchResult));
                break;
            case "track":
                collector.commit(new SoundcloudStreamInfoItemExtractor(searchResult));
                break;
            case "playlist":
                collector.commit(new SoundcloudPlaylistInfoItemExtractor(searchResult));
                break;
        }
    }

    return collector;
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:61,代码来源:SoundcloudSearchEngine.java


示例15: getSubtitles

import com.grack.nanojson.JsonParser; //导入依赖的package包/类
@Override
@Nullable
public List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException {
    assertPageFetched();
    if(isAgeRestricted) {
        // If the video is age restricted getPlayerConfig will fail
        return null;
    }
    // TODO: This should be done in onFetchPage()
    JsonObject playerConfig = getPlayerConfig(getPageHtml(NewPipe.getDownloader()));
    String playerResponse = playerConfig.getObject("args").getString("player_response");

    JsonObject captions;
    try {
        // Captions does not exist, return null
        if (!JsonParser.object().from(playerResponse).has("captions")) return null;

        captions = JsonParser.object().from(playerResponse).getObject("captions");
    } catch (JsonParserException e) {
        // Failed to parse subtitles
        return null;
    }
    JsonArray captionsArray = captions.getObject("playerCaptionsTracklistRenderer").getArray("captionTracks");

    int captionsSize = captionsArray.size();
    // Should not happen, if there is the "captions" object, it should always has some captions in it
    if(captionsSize == 0) return null;

    List<Subtitles> result = new ArrayList<>();
    for (int x = 0; x < captionsSize; x++) {
        String baseUrl = captionsArray.getObject(x).getString("baseUrl");

        String extension = format.getExtension();

        String URL = baseUrl.replaceAll("&fmt=[^&]*", "&fmt=" + extension);
        String captionsLangCode = captionsArray.getObject(x).getString("vssId");
        boolean isAutoGenerated = captionsLangCode.startsWith("a.");
        String languageCode = captionsLangCode.replaceFirst((isAutoGenerated) ? "a." : ".", "");

        result.add(new Subtitles(format, languageCode, URL, isAutoGenerated));
    }

    return result;
}
 
开发者ID:TeamNewPipe,项目名称:NewPipeExtractor,代码行数:45,代码来源:YoutubeStreamExtractor.java



注:本文中的com.grack.nanojson.JsonParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SpiDevice类代码示例发布时间:2022-05-23
下一篇:
Java Debugger类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap