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 8407927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:30:19+00:00 2026-06-09T23:30:19+00:00

I have a parsed a YouTube GDATA JSON-C file, and as such it is

  • 0

I have a parsed a YouTube GDATA JSON-C file, and as such it is JSON the duration of each video does not have the : in between (it is parsed as 23 or 432 instead of 0:23 or 4:32) how would i split a string before the last 2 characters without knowing the length as it can be anywhere from 2 – 6 strings

public class Uploads  extends Activity {

static final String KEY_VIDEOITEM = "item"; 
static final String KEY_VIDEOID = "id";
static final String KEY_VIDEOTITLE = "title";
static final String KEY_VIDEODESCRIPTION = "description";
static final String KEY_VIDEOCOUNT = "viewCount";
static final String KEY_VIDEODURATION = "duration";
static final String KEY_VIDEODURATIONFORMATTED = "duration";
static final String KEY_VIDEOTHUMB_URL = "thumb_url";
static final String KEY_VIDEOURL = "videourl";
static String Duration = "duration";

ListView list;
org.scouts.android.videos.LazyAdapter adapter;

/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video_lsitview);
    TextView lblTitle = (TextView) findViewById(R.id.actionbar);
    lblTitle.setText("Uploads");



    ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();

    //Get the data (see above)
    //JSONObject json = getJSON.getJSONfromURL("http://gdata.youtube.com/feeds/api/users/worldscouting/playlists?alt=jsonc");

    HttpClient client = new DefaultHttpClient();
    // Perform a GET request to YouTube for a JSON list of all the videos by a specific user
    HttpUriRequest request = new HttpGet("http://gdata.youtube.com/feeds/api/users/worldscouting/uploads?v=2&alt=jsonc");
    // Get the response that YouTube sends back
    HttpResponse response = null;
    try {
        response = client.execute(request);
    } catch (ClientProtocolException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    // Convert this response into a readable string
    String jsonString = null;
    try {
        jsonString = StreamUtils.convertToString(response.getEntity().getContent());
    } catch (IllegalStateException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    // Create a JSON object that we can use from the String
    JSONObject json = null;
    try {
        json = new JSONObject(jsonString);
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

           try{



               //JSONArray  earthquakes = json.getJSONObject("data").getJSONArray("items");
               JSONArray jsonArray = json.getJSONObject("data").getJSONArray("items");
                //Loop the Array
        for(int i=0;i < jsonArray.length();i++){                        

            HashMap<String, String> map = new HashMap<String, String>();
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            //JSONObject uploads = earthquakes.getJSONObject(i);

            map.put("id",  String.valueOf(i));
            map.put("videoid", jsonObject.getString("id"));

            map.put(KEY_VIDEOTITLE, jsonObject.getString(KEY_VIDEOTITLE));
            map.put(KEY_VIDEODESCRIPTION, jsonObject.getString(KEY_VIDEODESCRIPTION));
            map.put(KEY_VIDEOCOUNT, "Views: "+jsonObject.getString(KEY_VIDEOCOUNT));
            map.put(KEY_VIDEODURATION, jsonObject.getString(KEY_VIDEODURATION));
            map.put(KEY_VIDEOURL, jsonObject.getJSONObject("player").getString("mobile"));
            map.put(KEY_VIDEOTHUMB_URL, jsonObject.getJSONObject("thumbnail").getString("sqDefault"));


            mylist.add(map);




        }
           }catch(JSONException e)        {
             Log.e("log_tag", "Error parsing data "+e.toString());
           }




           list=(ListView)findViewById(R.id.videolist);         
           adapter=new org.scouts.android.videos.LazyAdapter(this, mylist);        
           list.setAdapter(adapter);

           list.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                String videourl = ((TextView) view.findViewById(R.id.video_id)).getText().toString();

                Uri uri = Uri.parse(videourl);
                startActivity( new Intent( Intent.ACTION_VIEW, uri ) );




    ;}});}}
  • 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-09T23:30:21+00:00Added an answer on June 9, 2026 at 11:30 pm

    public class string {
    public static void main(String[] args) {

    String str= "45";
    String op=addToString(str, ":");
    System.out.println(op);
    }
    static String addToString(String str,  String ins) {
        if(str.length()<=2)
        {
            str="00"+str;
        }
        int i = str.length()-(str.length()-2);
        return str.substring(0, i) + ins + str.substring(i);
    }
    

    }

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

Sidebar

Related Questions

I have parsed XML file into objects, in which each object has a 1:1
I have parsed a file in tcl and i read the line like that
Possible Duplicate: jQuery won't parse my JSON from AJAX query So I have parsed
I have a CSV file supplied from a client which has to be parsed
I have this regex for getting the YouTube video ID: (?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=[0-9]/)[^&\n]+|(?<=v=)[^&\n]+ I get it
I have parsed an xml file using the digester parser , now i need
I have parsed .ics file and get the start date as string , the
I have a returned JSON string which I have parsed and put through into
Since I don't have a flash player to play the video from Youtube itself,
I have the following code that grabs youtube's video id from the old share

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.