Click here to Skip to main content
15,911,039 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to extract the original link from a string. The string contains something like this

{
    "upload": {
        "image": {
            "name": false,
            "title": "",
            "caption": "",
            "hash": "cSNjk",
            "deletehash": "ZnKGru1reZKoabU",
            "datetime": "2010-08-16 22:43:22",
            "type": "image\/jpeg",
            "animated": "false",
            "width": 720,
            "height": 540,
            "size": 46174,
            "views": 0,
            "bandwidth": 0
        },
        "links": {
            "original": "http:\/\/imgur.com\/cSNjk.jpg",
            "imgur_page": "http:\/\/imgur.com\/cSNjk",
            "delete_page": "http:\/\/imgur.com\/delete\/ZnKGru1reZKoabU",
            "small_square": "http:\/\/imgur.com\/cSNjks.jpg",
            "large_thumbnail": "http:\/\/imgur.com\/cSNjkl.jpg"
        }
    }
}


how can i get the link that's right after original?
Posted
Updated 21-Aug-12 10:42am
v2
Comments
[no name] 21-Aug-12 15:54pm    
You could probably do it using a regular expression or String.IndexOf and Substring.
phantomlakshan 21-Aug-12 15:59pm    
I have no experience in Regular Expression or String.IndexOf. Can you please elaborate a little bit?

This looks like JSON data.
Get a JSON parser.
http://json.org/[^]
Near the bottom of the page there is a big list of JSON implementations.
Or see: JSON Serialization and Deserialization in ASP.NET[^]
 
Share this answer
 
Comments
phantomlakshan 21-Aug-12 16:27pm    
yOU ARE EXACTLY RIGHT. i'M TYING TO UPLOAD AN IMAGE TO IMGUR AND GET THE LINK OF THAT IMAGE. tHIS IS WHAT I GET FROM THE SERVER WHEN I UPLOAD
AN IMAGE
You can read this file line by line, or if it's a string, Split[^] it on Environment.NewLine. Then you can take each string and check if it contains your key, such as 'original'. If it does, you can split on the : and then grab the second string, or just Replace[^] "Original": with string.Empty. You can then replace " with string.Empty, and you will have your URL. It looks like you need to replace \/ with /, also.
 
Share this answer
 
I think you can use Remove() function for it.remove the index of "original".See how to use Remove()..
http://www.dotnetperls.com/remove[^]
http://msdn.microsoft.com/en-us/library/d8d7z2kk.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900