How can I match a GameObject to its resource ID in the .Unity scene file?

These are the file contents for a Unity scene

--- !u!1 &341095427
GameObject:
  m_ObjectHideFlags: 0
  m_PrefabParentObject: {fileID: 143402, guid: e58d4c3907fdc484faf3ab7001288374, type: 2}
  m_PrefabInternal: {fileID: 0}
  serializedVersion: 4
  m_Component:
  - 4: {fileID: 341095443}
  m_Layer: 8
  m_Name: Main Camera
  m_TagString: MainCamera
  m_Icon: {fileID: 0}
  m_NavMeshLayer: 0
  m_StaticEditorFlags: 0
  m_IsActive: 1

The serialized Id for this object is on the first line (341095427). My script is an editor invoked from a Unity menu. I am iterating through all of the GameObjects in the currently active scene. Is there a way to get the above Id for a GameObject? Unfortunately GetInstanceID() returns a different value.

using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Reflection;

public class testEditor
{
    [MenuItem("Test/PrintAllGO")]
    static void PrintAllGO()
    {
        PropertyInfo inspectorModeInfo = typeof(SerializedObject).GetProperty("inspectorMode", BindingFlags.NonPublic | BindingFlags.Instance);

        foreach(Object unityObject in GameObject.FindObjectsOfType<Object>())
        {
            SerializedObject serializedObject = new SerializedObject(unityObject);
            inspectorModeInfo.SetValue(serializedObject, InspectorMode.Debug, null);

            SerializedProperty localIdProp = serializedObject.FindProperty("m_LocalIdentfierInFile");

            int localId = localIdProp.intValue;
            Debug.Log(localId);
        }
    }
}

I found the answer here.