Get the image id from image cropper property

I am trying to get an image ID of the Umbraco's Image Cropper property in order to use it with TypedMedia(id).GetResponsiveCropUrl() method.

I am struggling to extract only the ID. My current implementation item.GetProperty("mainImage").Value.ToString() returns JSON object consisting of additional Image Cropper data such as focal point:

{ "focalPoint": { "left": 0.71111111111111114, "top": 0.57 }, "src": "/media/1004/9910_03_7326-river-flood_web.jpg", "crops": [ { "alias": "Carousel", "width": 700, "height": 400 } ] }1156

What would be the best approach for retrieving the image ID?

This is my implementation:

 foreach (Node item in Node.GetCurrent().GetDescendantNodes())
 {
    if (item.GetProperty<bool>("showInNewsCarousel") == true)
    {
        Response.Write(item.GetProperty("mainImage").Value.ToString());
    //    var slideImage = Umbraco.Media(item.GetProperty("mainImage").Value);
        <img class="img-responsive" src="@Umbraco.TypedMedia(1155).GetResponsiveCropUrl("Carousel")" />
    }
}

Answers


The 1156 value that you said in the comments was the image ID is not actually part of the JSON, but appears to have been tacked on later. (If you try to validate the string at JSONLint.com, you'll see what I mean.) Since the ID is not part of the JSON, you will not be able to use a JSON parser to get the value. I think your best bet is just to find the last closing brace and then take everything after that.

string id = json.Substring(json.LastIndexOf('}') + 1).Trim();

Need Your Help

Criteria question with NHibernate

nhibernate criteria

I'm trying to use NHibernate for data access, and I have 2 simple entities that look like this:

AWS OpsWorks - Linux drive to S3 Bucket

php linux amazon-web-services amazon-s3 amazon-ec2

What would be the best way to 'symlink' pe-say a drive on an AWS linux instance to an S3 bucket?