Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8377523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:41:33+00:00 2026-06-09T15:41:33+00:00

My problem is I receive an JSON text from say, twitter. Then I want

  • 0

My problem is I receive an JSON text from say, twitter. Then I want to convert this text to an native object in scala. Is there a standard method to do this? I’m also using Play 2

Here is what I have

import scala.io.Source.{fromInputStream}
import java.net._

val url = new URL("https://api.twitter.com/1/trends/1.json")
val content = fromInputStream( url.openStream ).getLines.mkString("\n")
val json = Json.parse(content)
val a = (json \ "trends" )
Ok(a(0))

I want to get all the trends name from the JSON

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:41:34+00:00Added an answer on June 9, 2026 at 3:41 pm

    I personally prefer lift-json, but it’s pretty easy to do this with Play’s JSON library:

    import play.api.libs.json._
    import scala.io.Source
    
    case class Trend(name: String, url: String)
    
    implicit object TrendReads extends Reads[Trend] {
      def reads(json: JsValue) = Trend(
        (json \ "name").as[String],
        (json \ "url").as[String]
      )
    }
    
    val url = new java.net.URL("https://api.twitter.com/1/trends/1.json")
    val content = Source.fromInputStream(url.openStream).getLines.mkString("\n")
    val trends = Json.parse(content) match {
      case JsArray(Seq(t)) => Some((t \ "trends").as[Seq[Trend]])
      case _ => None
    }
    

    Right now this produces the following:

    scala> trends.foreach(_.foreach(println))
    Trend(#TrueFactsAboutMe,http://twitter.com/search/?q=%23TrueFactsAboutMe)
    Trend(#200mFinal,http://twitter.com/search/?q=%23200mFinal)
    Trend(Jamaica 1,2,3,http://twitter.com/search/?q=%22Jamaica%201,2,3%22)
    Trend(#DontComeToMyHouse,http://twitter.com/search/?q=%23DontComeToMyHouse)
    Trend(Lauren Cheney,http://twitter.com/search/?q=%22Lauren%20Cheney%22)
    Trend(Silver & Bronze,http://twitter.com/search/?q=%22Silver%20&%20Bronze%22)
    Trend(Jammer Martina,http://twitter.com/search/?q=%22Jammer%20Martina%22)
    Trend(Japan 2-0,http://twitter.com/search/?q=%22Japan%202-0%22)
    Trend(Prata e Bronze,http://twitter.com/search/?q=%22Prata%20e%20Bronze%22)
    Trend(Final 200m,http://twitter.com/search/?q=%22Final%20200m%22)
    

    So yeah, looks about right.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to receive a JSON object using Ruby. I've written this: require 'sinatra'
I'm having a problem where I receive this error: Exception in thread main java.lang.NullPointerException
I am having a problem with formatting a date that I receive from a
I can successfully receive email from SendGrid and process its data. My problem is
I have a problem with my iOS application. I receive binary vector data from
When attempting to use pandoc to convert JSON based files (.ipynb) from iPython notebook
I need to call a web service to receive a JSON object which I'll
My problem is really simple but I'm not sure if there's a native solution
I want to POST an Object via JSON to node.js server. The Object structure
I want to send array from php to jquery using json. the array in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.