none
How to parse musixmatch synced lyrics(subtitles)? RRS feed

  • Question

  • (C#) (UWP) How to parse musixmatch synced lyrics from JSON/XML

    this is the json response

    {"message":{"header":{"status_code":200,"execute_time":0.0088448524475098},"body":{"subtitle":{"subtitle_id":26648877,"restricted":0,"subtitle_body":"[{\"text\":\"You give me love now unconditional\",\"time\":{\"total\":19.04,\"minutes\":0,\"seconds\":19,\"hundredths\":4}},{\"text\":\"My heart condition nearly critical\",\"time\":{\"total\":24.07,\"minutes\":0,\"seconds\":24,\"hundredths\":7}},{\"text\":\"You make me stronger than I've ever been before\",\"time\":{\"total\":27.07,\"minutes\":0,\"seconds\":27,\"hundredths\":7}},{\"text\":\"But oh so weak in the knees falling to the floor\",\"time\":{\"total\":31.08,\"minutes\":0,\"seconds\":31,\"hundredths\":8}},{\"text\":\"Afraid I'll lose myself deep in your eyes\",\"time\":{\"total\":37.03,\"minutes\":0,\"seconds\":37,\"hundredths\":3}},{\"text\":\"Then all at once I'm found and recognized\",\"time\":{\"total\":41.03,\"minutes\":0,\"seconds\":41,\"hundredths\":3}},{\"text\":\"Uh-oh you caught me honey unbelievable\",\"time\":{\"total\":45.08,\"minutes\":0,\"seconds\":45,\"hundredths\":8}},{\"text\":\"Now that you got my oh it's unmistakable\",\"time\":{\"total\":49.06,\"minutes\":0,\"seconds\":49,\"hundredths\":6}},{\"text\":\"Oh, all the feels\",\"time\":{\"total\":54.02,\"minutes\":0,\"seconds\":54,\"hundredths\":2}},{\"text\":\"Oh, feels so real\",\"time\":{\"total\":59.07,\"minutes\":0,\"seconds\":59,\"hundredths\":7}},{\"text\":\"All the emotions flood like the ocean\",\"time\":{\"total\":63.02,\"minutes\":1,\"seconds\":3,\"hundredths\":2}},{\"text\":\"Oh, all the feels\",\"time\":{\"total\":68.06,\"minutes\":1,\"seconds\":8,\"hundredths\":6}},{\"text\":\"Feel my cheeks blush each time your gaze meets mine\",\"time\":{\"total\":89,\"minutes\":1,\"seconds\":29,\"hundredths\":0}},{\"text\":\"Get all a-flutter feeling butterflies\",\"time\":{\"total\":93.07,\"minutes\":1,\"seconds\":33,\"hundredths\":7}},{\"text\":\"Shot to the heart with all of your cupids arrows\",\"time\":{\"total\":97.03,\"minutes\":1,\"seconds\":37,\"hundredths\":3}},{\"text\":\"I'm flying higher with my own Romeo\",\"time\":{\"total\":101.06,\"minutes\":1,\"seconds\":41,\"hundredths\":6}},{\"text\":\"Oh, all the feels\",\"time\":{\"total\":106.06,\"minutes\":1,\"seconds\":46,\"hundredths\":6}},{\"text\":\"Oh, feels so real\",\"time\":{\"total\":111.01,\"minutes\":1,\"seconds\":51,\"hundredths\":1}},{\"text\":\"All the emotions flood like the ocean\",\"time\":{\"total\":115.09,\"minutes\":1,\"seconds\":55,\"hundredths\":9}},{\"text\":\"Oh, all the feels\",\"time\":{\"total\":120.03,\"minutes\":2,\"seconds\":0,\"hundredths\":3}},{\"text\":\"Oh, all the feels\",\"time\":{\"total\":142.02,\"minutes\":2,\"seconds\":22,\"hundredths\":2}},{\"text\":\"Oh, feels so real\",\"time\":{\"total\":146.07,\"minutes\":2,\"seconds\":26,\"hundredths\":7}},{\"text\":\"All the emotions flood like the ocean\",\"time\":{\"total\":150.02,\"minutes\":2,\"seconds\":30,\"hundredths\":2}},{\"text\":\"Oh, all the feels\",\"time\":{\"total\":154.03,\"minutes\":2,\"seconds\":34,\"hundredths\":3}},{\"text\":\"Oh, all the feels\",\"time\":{\"total\":159.04,\"minutes\":2,\"seconds\":39,\"hundredths\":4}},{\"text\":\"Oh, feels so real\",\"time\":{\"total\":163.03,\"minutes\":2,\"seconds\":43,\"hundredths\":3}},{\"text\":\"All the emotions flood like the ocean\",\"time\":{\"total\":167.09,\"minutes\":2,\"seconds\":47,\"hundredths\":9}},{\"text\":\"Oh, all the feels\",\"time\":{\"total\":172.09,\"minutes\":2,\"seconds\":52,\"hundredths\":9}},{\"text\":\"All the feels\",\"time\":{\"total\":192.09,\"minutes\":3,\"seconds\":12,\"hundredths\":9}},{\"text\":\"\",\"time\":{\"total\":195.06,\"minutes\":3,\"seconds\":15,\"hundredths\":6}}]","subtitle_avg_count":0,"lyrics_copyright":"","subtitle_length":203,"subtitle_language":"en","subtitle_language_description":"English","script_tracking_url":"https://tracking.musixmatch.com/t1.0/m_js/e_0/sn_0/l_0/su_26648877/rs_0/tr_3vUCADB-H4nJCsOhqF_jZz2n-smOMpkuRGBlkEWDqGgZHXBdac9GpaPsOnpZQW104bT2IoJVmcSW3HwbWet6dUGaEA0mHbNwJYRA-rgYCzGLhgeV_cTgsyyvBMhoSuE3xEjykl39Bz_Vw6DJ6XzqDewWy2E9YltQAVnUn1Tqqj81FG_mbPtgooISncM1Ydkgt2iiT4N7RJMoYJqih8nX_R-l_oKm-meGHQjvq0Dcxlsy5nT65GYiOuCPXX9Ssp2IqnXStolMu2Dp8Dzdqrqs1KIlmLNwa13MhyV7Po4xc5Lq99NZVyHm-r5i8rR3QdDtRNWO8Ob5A3A_NAvgnAYgnzTY30fVk8Ih8iStL61ElktpUvE2qjnQwm93JtF25iLDTM2fYKwrFYhXXsVVsBPzlfISzk6eSwjO2IYA4pDkM8-RFf4DMR_mExWzYhHCSbOJIEIQHrWSmnegHt6BbZMI97eXruYblVqv85XoW0WzPE3HXQBtykY2sBP2vd3kO_xSEf_TFevFEaNJss1thrWFSy5lZ4N8A2h1NRE6be5sZ7Xh5x0VN4NGNqD-fgvvIfnSK11uF2ZYccnSxiYa7w/","pixel_tracking_url":"https://tracking.musixmatch.com/t1.0/m_img/e_0/sn_0/l_0/su_26648877/rs_0/tr_3vUCAEJ3yV4rS0vza7JOuyY9WCg-Q17bH7-N5bObDS2J21jYGGY_OkPhVmeZU7aNaNtXpih1mQn_LrS0rD2lhQX5yo-bc_fqfUaM8RzHnpaDpkEtBeqyjToL7Slieu8PTcPQNPkshiIXdG2Jjhx2uSntSBzVrOaAacnM8zb-digBVk2NblAOOxkHKvbKftdp5WAznnGBvOFwgvfsdn6EQVPEClU2yUGhb1QvV2Uqv2gsk-66UsxtesIzsAULATLKdvGGfFZbmFfhW9gOdyLoT8pOn-mdizI2pOkpFisG09SZWY6XgjihYlQ56mXWOC0-Q0OqPMGocg3d-9nyJnwgs8JzyDe6ov_ep2RpCfnJD8Bpnq4AQ8uSUxiZDu6XzsbHQW5pZvENh_9879l6qkOHgjG1NjouJm4AGBHlTVQACxQsyrXMSoN9TVlJMQc2-7F7rPozdXICof9yZHi6xY9S3fjJhdqJAPizoclsCfpMcMNiBEG4sffKNrEvEhhHNBjFvn3FtS2u1z8DQtp7wmC1f4pyhuZshcxrUfWMYB-lUEz_YhqZOGzQBjkSER8ipVHnw5_bMDqKVy3cdxCSqg/","html_tracking_url":"https://tracking.musixmatch.com/t1.0/m_html/e_0/sn_0/l_0/su_26648877/rs_0/tr_3vUCACklG-an_dskyzcF0GmWrYD-DPAv3Fz7tIzLXcgd2qUJiA6aBCt02PmMnVhIvYbjdHt2O32RyVZQOK0ccFYY94o7FDEdnfZUQmzu0U0xsdn3u-Fob4GDdT89imZTgB6vC7WYq0NDAtfPY5ZBwtCTT7or-7cMZUj6nMFOUcpUk6K66FM3HCGU75KMJ9EyXNea4pCvWJeBUUldVv5WSuimizXD0RQ2j3Nu_g2ToU9-Y61JS5cnw69DasDnqu_g5AKcRYzJU1rI9vejgIL-3OnOTQo3SVMZztCY2AvMPH0IQComgzmUwcvf2Sbd5MwYcVbwxDj1XuWkWDIKWB3rAx2W2Z99-N9MD6t2Mo3ItkiGVsTluJ-aBy24CU_Q4OGKMcV7GAxK-9GEOHnlEaGnDKyyHaUeMjriG4P0BNHWXCg3SvAv5lKP94TR1HikdoPh5hAxJwojZILVGJt5IkaM0AMWuXABo0ap33R3r5hjKJDDjPgLxd6HQv0wwcWZhAuYKKHXo3tZwGKHWKyPcj4FeUkM8-7-joKAIyil6Y1q25zhsVPq561WMBlt9JTlZMwWtYjWXHYY_S_kT2awxA/","writer_list":[],"publisher_list":[],"updated_time":"2019-06-05T01:02:22Z"}}}}

    Now I want to get the content from subtitle_body and and put it into label element and sync it with time (I mean parsing this {\"total\":24.07,\"minutes\":0,\"seconds\":24,\"hundredths\":7}}) to get something like what musixmatch app does

    and also (optional) convert it to SRT subtitles file

    Thanks.

    Tuesday, June 11, 2019 9:18 PM

Answers

  • Hi,

    Well, if you need to deserialize JSON objects, you could use JsonObject class. First, you need to create a class that use to storage the json data. For example, like this:

    public class Header
    {
        public int status_code { get; set; }
        public double execute_time { get; set; }
    }
    
    public class Subtitle
    {
        public int subtitle_id { get; set; }
        public int restricted { get; set; }
        public string subtitle_body { get; set; }
        public int subtitle_avg_count { get; set; }
        public string lyrics_copyright { get; set; }
        public int subtitle_length { get; set; }
        public string subtitle_language { get; set; }
        public string subtitle_language_description { get; set; }
        public string script_tracking_url { get; set; }
        public string pixel_tracking_url { get; set; }
        public string html_tracking_url { get; set; }
        public List<object> writer_list { get; set; }
        public List<object> publisher_list { get; set; }
        public DateTime updated_time { get; set; }
    }
    
    public class Body
    {
        public Subtitle subtitle { get; set; }
    }
    
    public class Message
    {
        public Header header { get; set; }
        public Body body { get; set; }
    }
    
    public class RootObject
    {
        public Message message { get; set; }
    }

    Then you will need to use JsonObject to parse the data string.

    Like this:

    JsonObject jsonObject = JsonObject.Parse(jsonString);
    Message jsmessage = jsonObject.GetNamedString("", null);
    There is an official here : JSON sample that you could refer. It contains the complete process about parsing the Json. 

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Ahmed Walid Wednesday, June 12, 2019 4:39 PM
    Wednesday, June 12, 2019 3:31 AM
    Moderator